MySQL workbench 導出異常解決方案

MySQL version:8.0.13

MySQL workbench :8.0.13

使用Export Data時報:Could not get mysqldump version,具體如下:

首先,通過 Help -> Locate Log Files 找到 workbench 的日誌文件所在位置 ~/.mysql/workbench/log ,查看 wb.log 文件中的內容,看到下面一句:

22:22:40 [ERR][wb_admin_export.py:get_mysqldump_version:117]: Could not parse version number from mysqldump:
mysqldump  Ver 8.0.13 for Linux on x86_64 (MySQL Community Server - GPL)

估計應該是解析版本時發生錯誤導致了錯誤提示,順藤摸瓜,查到一個靠譜的說是wb_admin_control.py中的正則表達式有錯誤導致的,可那是6.3版本的,在8.0.13的該文件中不存在類似代碼,故將當前目錄設定爲 /usr/lib/mysql-workbench/modules/ ,然後使用 grep -r parse ./ 命令查找所有包含parse的所有文件。查到的結果中有如下一段內容:

./wb_admin_export.py:        log_error("Could not parse version number from %s:\n%s"%(path, output))

這部分代碼與wb.log中的內容相符,故檢查 wb_admin_export.py 文件。發現其中一段代碼如下:

def get_mysqldump_version():
    path = get_path_to_mysqldump()
    if not path:
        log_error("mysqldump command was not found, please install it or configure it in Edit -> Preferences -> MySQL")
        return None
      
    output = StringIO.StringIO()
    rc = local_run_cmd('"%s" --version' % path, output_handler=output.write)
    output = output.getvalue()
    
    if rc or not output:
        log_error("Error retrieving version from %s:\n%s (exit %s)"%(path, output, rc))
        return None
      
    s = re.match(".*Distrib ([\d.a-z]+).*", output)
    
    if not s:
        log_error("Could not parse version number from %s:\n%s"%(path, output))
        return None
    
    version_group = s.groups()[0]
    major, minor, revision = [int(i) for i in version_group.split(".")[:3]]
    return Version(major, minor, revision)

其中, s = re.match(".*Distrib ([\d.a-z]+).*", output) 代碼應該是用正則表達式提取版本號,使用mysqldump --versiion命令,查看dump版本號:

root@ONE:/usr/lib/mysql-workbench/modules$ mysqldump --version
mysqldump  Ver 8.0.13 for Linux on x86_64 (MySQL Community Server - GPL)

可以看出版本號內容與之前的正則表達式不匹配,修正正則表達式如下:

s = re.match(".*mysqldump  Ver ([\d.]+).*", output)

修正保存後,重啓workbench,一切都好了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章