To create a script of your database model use the
Export option found under the
File menu. You may export a script to alter an
existing database or create a new database. The script to create a
database is similar to the one created using the
mysqldump db_name
command.
If you choose to create a database, there are a number of export options that you may choose from.
Selecting File, Export, Forward Engineer SQL CREATE Script will start the Forward Engineer SQL Script wizard. The first page of the wizard is:
The SQL Export Options displays the following facilities:
Output SQL Script File
You can enter the name of your output file by entering it into the Output SQL Script File text box, or by using the Browse button to select a file. If this text box is left blank you will be able to view the generated script, but it will not be saved to a file.
Generate DROP Statements Before Each CREATE Statement
Omit Schema Qualifier in Object Names
Generate Separate CREATE INDEX Statements
Choosing this option creates separate statements for index
creation instead of creating indexes as part of a
CREATE TABLE
statement.
Add SHOW WARNINGS after every DDL statement
Do Not Create Users. Only Export Privileges
To update the privileges of existing users as opposed to
creating new users, select this check box. Exporting privileges
for nonexistent users will result in errors when you execute the
CREATE
script. Exporting users that already
exist, will also result in an error.
Generate INSERT Statements for Tables
If you have added any records to a table using the Insert tab of the MySQL Table Editor, choose this option. For more information about inserting records see Section 7.5.1.3.9, “The Inserts Tab”.
Clicking Next takes you to the SQL Object Export Filter page where you can select the objects you wish to export.
Precise control over the objects to be exported can be fine tuned by clicking the Show Filter button. Once the objects to be exported have been selected it is possible to reduce the expanded panel by clicking the same button, now labelled Hide Filter.
Having selected the objects you wish to export you can click the Next button to review the script that has been generated:
The Finish button saves the script file and exits. You may return to the previous screen using the Back button.
You can then use the saved script to create a database.
The menu option for altering a schema, Forward Engineer SQL ALTER Script ..., is used for updating a database that has been redesigned within MySQL Workbench. Typically, this option is used when the SQL script of a database has been imported into MySQL Workbench and changed, and then you want to create a script that can be run against a database to alter it to reflect the adjusted model. For instructions on importing a DDL script see Section 7.5.9.1, “Reverse Engineering Using a Create Script”.
Select File, Export, Forward Engineer SQL ALTER Script to start the Foward Engineer an ALTER Script wizard. You will be presented with the first page:
This first screen allows you to select a SQL script and compare it with the model currently in MySQL Workbench. The difference between the two models will be used to create an alter script that can be used to modify the target schema so that it matches the model held in MySQL Workbench. You can also simply view the script generated, rather than saving it to a file, by leaving the Output File text box empty.
The script selected as the Input File must use full schema
qualifiers, such as schema_name.table_name
,
otherwise MySQL Workbench will not be able to generate a useable
alter script.
Pressing Next brings you to the Review SQL Script screen.
Here you can review and change the alter script that will be
generated. Make any changes you wish and, if you are happy with
the changes, save the ALTER
script to file
using the Save to File ... button. You
can also click the Execute button to
write the script to the previously specified output file.
The generated script can then be used to update the database.