Gedean Dias
Gedean Dias

Reputation: 1103

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

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.

Upvotes: 5

Views: 4742

Answers (2)

madhead
madhead

Reputation: 33392

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.

Upvotes: 4

MySQL Workbench
MySQL Workbench

Reputation: 11

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

Upvotes: 0

Related Questions