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

2

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.

Acclamation answered 13/7, 2010 at 21:30 Comment(4)
Please could you clarify why that is a problem and what you are trying to do?Prudish
Without Workbench's command line capacity, how can I automate the building operation?Acclamation
What are you using Workbench for? It doesn't have a command line interface as far as I am aware.Prudish
mysql has a command line though, which is probably what he's referring toRovit
L
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.

Litotes answered 5/12, 2013 at 17:37 Comment(1)
Thanks ! This basically works (and I have incorporated your answer into my question's answer as well), though there are some minor errors in your script: It should read DbMySQLFE.generateSQLCreateStatements(c, c.version, {}) and + '/ddl.sql'.Mullion
S
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
Spinel answered 5/8, 2010 at 20:29 Comment(1)
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.Follett

© 2022 - 2024 — McMap. All rights reserved.