问题
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