Create database on the server via mysql-workbench template (.mwb) via command line

8

I'm trying to build a bat to create the database in the mysql server from a mysql-workbench EER (.mwb) model, that is, in command line, is it possible to perform this process? Could someone give a light?

Editing:

Opening it in cmd I have the following:

MySQLWorkbench [<options>] [<name of a model file or sql script>]
Options:
  --query [<connection>|<connection string>]
                          Open a query tab and ask for connection if nothing is specified.
                          If named connection is specified it will be opened,
                          else connection will be created based on the given connection string,
                          which should be in form <user>@<host>:<port>
  --admin <instance>      Open a administration tab to the named instance
  --upgrade-mysql-dbs     Open a migration wizard tab
  --model <model file>    Open the given EER model file
  --script <sql file>     Open the given SQL file in an connection, best in conjunction 
                          with a query parameter
  --run-script <file>     Execute Python code from a file
  --run <code>            Execute the given Python code
  --run-python <code>     Execute the given Python code
  --migration             Open the Migration Wizard tab
  --quit-when-done        Quit Workbench when the script is done
  --log-to-stderr         Also log to stderr
  --help, -h              Show command line options and exit
  --log-level=<level>     Valid levels are: error, warning, info, debug1, debug2, debug3
  --verbose, -v           Enable diagnostics output
  --version               Show Workbench version number and exit
  --open <file>           Open the given file at startup (deprecated, use script, model etc.)

Then you could use --model plus the --run-script and then --quit-when-done, but in that case what would this script look like in that language? Any tips on how to write it?

Issue 2

I found a similar question in the English OS, there really does not seem to be a way to do that.

link

Issue 3

Of course there is a response, after searching I put it down if anyone needs it.

    
asked by anonymous 02.06.2015 / 19:05

3 answers

3

So after a lot of searching I was able to do the bat, really the script to be used was in python, I had to learn a little python. I know that I can not answer my own answer that is rewarded, but since I did not get a satisfactory answer I will put it here and also to help in case anyone needs it. Following the main lines, you can customize and create a bat with arguments and other things depending on your preferred language. Thank you all for your help.

"C:\Program Files (x86)\MySQL\MySQL Workbench CE 6.1.7\MySQLWorkbench.exe" -model "C:\ModelosERR.mwb" -run-python "import os;import grt;from grt.modules import DbMySQLFE as MySQLFE;c = grt.root.wb.doc.physicalModels[0].catalog;MySQLFE.generateSQLCreateStatements(c, c.version, {});MySQLFE.createScriptForCatalogObjects(r'C:\temp.sql', c, {})" -quit-when-done

"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe" -u root -proot < "C:\temp.sql"
    
16.06.2015 / 00:32
3

I'll give you the path of the stones, but I will not write the whole .bat file here.

  • the .mwb file is a compressed file, renames it to .zip, and unzips it.
  • search for the .xml file and open it in a text editor
  • Within this file you have all the Tag's tags needed to build your .sql that will then dump into mysql.

    So, yes, how do I, and not, I will not manipulate this file, you choose the best technique and apply it on top of this xml file, does replace in hand, uses php xml to array, does json, I'll leave the example of how the mwb file gets after it has been unzipped:

        <?xml version="1.0"?>
    <data grt_format="2.0" document_type="MySQL Workbench Model" version="1.4.4">
      <value type="object" struct-name="workbench.Document" id="{A6AEAF1F-556E-433D-9483-5253F37D41EE}" struct-checksum="0x7131bf99">
        <value type="object" struct-name="workbench.logical.Model" id="{3183BE53-D18E-4B6F-AD8A-AE08B7BD19A2}" struct-checksum="0xf4220370" key="logicalModel">
          <value _ptr_="0B831168" type="list" content-type="object" content-struct-name="workbench.logical.Diagram" key="diagrams"/>
          <value _ptr_="0B8313E8" type="dict" key="customData"/>
          <value _ptr_="0B832C98" type="list" content-type="object" content-struct-name="model.Marker" key="markers"/>
          <value _ptr_="0B8308F8" type="dict" key="options"/>
          <value type="string" key="name"></value>
          <link type="object" struct-name="GrtObject" key="owner">{A6AEAF1F-556E-433D-9483-5253F37D41EE}</link>
        </value>
        <value _ptr_="0B831348" type="list" content-type="object" content-struct-name="workbench.OverviewPanel" key="overviewPanels"/>
        <value _ptr_="0B830E98" type="list" content-type="object" content-struct-name="workbench.physical.Model" key="physicalModels">
          <value type="object" struct-name="workbench.physical.Model" id="{2E273679-67EA-48F4-A08F-92A272B4D13F}" struct-checksum="0x5f896d18">
            <value type="object" struct-name="db.mysql.Catalog" id="{ECE8278F-2DB8-4352-B627-6552022356F5}" struct-checksum="0x82ad3466" key="catalog">
              <value _ptr_="0B831398" type="list" content-type="object" content-struct-name="db.mysql.LogFileGroup" key="logFileGroups"/>
              <value _ptr_="0B830858" type="list" content-type="object" content-struct-name="db.mysql.Schema" key="schemata">
                <value type="object" struct-name="db.mysql.Schema" id="{5278BE8F-6DD9-4F97-978C-C55DFCEE2B47}" struct-checksum="0x20b94c22">
                  <value _ptr_="0B8312F8" type="list" content-type="object" content-struct-name="db.mysql.RoutineGroup" key="routineGroups"/>
                  <value _ptr_="0B831C58" type="list" content-type="object" content-struct-name="db.mysql.Routine" key="routines">
                    <value type="object" struct-name="db.mysql.Routine" id="{7BB0B591-6EA6-409B-8F04-24B8E9076FA4}" struct-checksum="0x991f611c">
                      <value _ptr_="0B8318E8" type="list" content-type="object" content-struct-name="db.mysql.RoutineParam" key="params">
                        <value type="object" struct-name="db.mysql.RoutineParam" id="{C7FBF5C3-B6D8-43F5-9927-68FCC119125F}" struct-checksum="0x3f238dee">
                          <value type="string" key="datatype">INT</value>
                          <value type="string" key="paramType">IN</value>
                          <value type="string" key="name">cpf</value>
                          <link type="object" struct-name="GrtObject" key="owner">{7BB0B591-6EA6-409B-8F04-24B8E9076FA4}</link>
                        </value>
                      </value>
                      <value type="string" key="returnDatatype"></value>
                      <value type="string" key="security"></value>
                      <value type="string" key="name">duplicadoCpf</value>
                      <value type="string" key="routineType">procedure</value>
                      <value type="int" key="sequenceNumber">0</value>
                      <value type="string" key="definer">marcio'@'%</value>
                      <value type="string" key="sqlBody">BEGIN
        DECLARE EXIT HANDLER FOR SQLSTATE '23000'
        BEGIN
        SELECT 'CPF CADASTRADO PARA OUTRO MOTORISTA' AS Msg;
        END;
        INSERT INTO tab_proprietario SET prop_cpf = cpf;
        END</value>
                      <value type="string" key="sqlDefinition">
    
    CREATE DEFINER='marcio'@'%' PROCEDURE 'duplicadoCpf'(IN cpf INT)
    BEGIN
        DECLARE EXIT HANDLER FOR SQLSTATE '23000'
        BEGIN
        SELECT 'CPF CADASTRADO PARA OUTRO MOTORISTA' AS Msg;
        END;
        INSERT INTO tab_proprietario SET prop_cpf = cpf;
        END</value>
                      <value type="int" key="commentedOut">0</value>
                      <value type="string" key="createDate">2013-04-17 09:17</value>
                      <value _ptr_="0B831578" type="dict" key="customData"/>
                      <value type="string" key="lastChangeDate">2013-09-05 08:06</value>
                      <value type="int" key="modelOnly">0</value>
                      <link type="object" struct-name="GrtNamedObject" key="owner">{5278BE8F-6DD9-4F97-978C-C55DFCEE2B47}</link>
                      <value type="string" key="temp_sql"></value>
                      <value type="string" key="comment"></value>
                      <value type="string" key="oldName">duplicadoCpf</value>
                    </value>
    .
    .
    .
    

    Good luck!

      

    And here the quote from the source give credit to who deserves link

        
    13.06.2015 / 02:46
    1

    My answer may not be right for you. I've been working with MySql Workbench since the beta and have never seen anything like it. I think that's not even possible.

    Something I usually use is the Synchronize Model, which takes your mwb and compares it to the database of the connection you selected. This is useful both to replicate change and to create the entire template from scratch.

    If I have any questions about this process, I'll explain it here.

    Now it is possible to execute a sql file using the mysql cli, so you would need to export your mwb to an sql file.

        
    10.06.2015 / 16:08