5

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.

Gedean Dias
  • 1,063
  • 1
  • 10
  • 24

2 Answers2

4

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.

madhead
  • 31,729
  • 16
  • 153
  • 201
  • 2
    Thanks ! This basically works (and I have incorporated your answer into [my question's answer](http://stackoverflow.com/a/26914679/419404) as well), though there are some minor errors in your script: It should read `DbMySQLFE.generateSQLCreateStatements(c, c.version, {})` and `+ '/ddl.sql'`. – Arc Nov 13 '14 at 17:23
0

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
  • 2
    Tnx for the link. I will surely check this API out. It'd be definitely a cool feature to have a CLI app also, which could generate SQL from mwb files. So DB schemas could be designed using the MySQL Workbench GUI, and then a single click automated deployment procedure (during development, I mean) could do everything on the db schema. Keeping everything DRY compliant. But I'm confident this can all be done through the Python API mentioned above. – maraspin Dec 10 '10 at 11:07