How to generate SQL Script from MySQL Workbench using Command Line?

流过昼夜 提交于 2019-12-12 11:15:07

问题


I'm currently using FinalBuilder to create a one-click building n’ generate install, but I faced with MySQL Workbench lack of capacity to generate SQL script from a command line.


回答1:


You can actually automate this task with Python (or Lua) script - MySQL Workbench already has an interpreter under Scripting menu. Create a new script and use the stub:

# -*- coding: utf-8 -*-

import os
import grt
from grt.modules import DbMySQLFE

c = grt.root.wb.doc.physicalModels[0].catalog
DbMySQLFE.generateSQLCreateStatements(c, c.version, {
    'GenerateDrops' : 1,
    'GenerateSchemaDrops' : 1,
    'OmitSchemata' : 1,
    'GenerateUse' : 1
})
DbMySQLFE.generateSQLCreateStatements(c, c.version, {
DbMySQLFE.createScriptForCatalogObjects(os.path.dirname(grt.root.wb.docPath) + 'ddl.sql', c, {})

It does not actully run from command line, but I beleive you can run it with --run-script option.




回答2:


MySQL Workbench has a full Python Scripting API.

If you need additional features, please let us know: http://forums.mysql.com/index.php?151

  • MySQL Workbench


来源:https://stackoverflow.com/questions/3241712/how-to-generate-sql-script-from-mysql-workbench-using-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!