|
|
@@ -19,6 +19,7 @@ Options:
|
|
|
"""
|
|
|
import logging
|
|
|
import re
|
|
|
+import subprocess
|
|
|
from subprocess import Popen, PIPE, CalledProcessError
|
|
|
import sys
|
|
|
|
|
|
@@ -73,6 +74,17 @@ def _print(msg, end=False):
|
|
|
print(f'\r{msg}', end='' if not end else '\n', flush=True)
|
|
|
|
|
|
|
|
|
+def fetch_mysqldump_version():
|
|
|
+ p = subprocess.run('mysqldump --version', shell=True, capture_output=True)
|
|
|
+ out, err = p.stdout.decode('utf-8'), p.stderr.decode('utf-8')
|
|
|
+ if err:
|
|
|
+ raise RuntimeError('mysqldump can not be found, is it installed on this machine?')
|
|
|
+ fork = "mariadb" if "MariaDB" in out else "mysql"
|
|
|
+ match = re.search(r"Ver ((?:\d+\.?)+)", out)
|
|
|
+ version = match.group(1) if match else "0"
|
|
|
+ return fork, version
|
|
|
+
|
|
|
+
|
|
|
class MysqldumpHandler(PipeHandler):
|
|
|
""" Handle and process the stdout / stderr output from a mysqldump process
|
|
|
"""
|
|
|
@@ -305,6 +317,8 @@ class CloningOperation:
|
|
|
tables = tables or []
|
|
|
dump_options = dump_options or []
|
|
|
|
|
|
+ mysqldump_version = fetch_mysqldump_version()
|
|
|
+
|
|
|
base_cmd = ["mysqldump",
|
|
|
"--single-transaction",
|
|
|
"-u", self.from_server.username,
|
|
|
@@ -316,12 +330,14 @@ class CloningOperation:
|
|
|
]
|
|
|
|
|
|
# <-- fix the occasional 'Unknown table 'COLUMN_STATISTICS' in information_schema' bug
|
|
|
- try:
|
|
|
- self.from_server.exec_query("SELECT COLUMN_NAME FROM information_schema.COLUMN_STATISTICS;")
|
|
|
- except pymysql.err.OperationalError:
|
|
|
- base_cmd.append("--column-statistics=0")
|
|
|
- except pymysql.err.MySQLError:
|
|
|
- pass
|
|
|
+ # https://stackoverflow.com/questions/52423595/mysqldump-couldnt-execute-unknown-table-column-statistics-in-information-sc
|
|
|
+ if mysqldump_version[0] == 'mysql' and mysqldump_version[1] >= "8":
|
|
|
+ try:
|
|
|
+ self.from_server.exec_query("SELECT COLUMN_NAME FROM information_schema.COLUMN_STATISTICS;")
|
|
|
+ except pymysql.err.OperationalError:
|
|
|
+ base_cmd.append("--column-statistics=0")
|
|
|
+ except pymysql.err.MySQLError:
|
|
|
+ pass
|
|
|
# -->
|
|
|
|
|
|
if self.compress:
|