9.4.2.1 Reverse Engineering Using a Create Script
To reverse-engineer a database using a create script, do one of the following:
On the home screen, select the model view from the sidebar, click (>) next to Models, and then click .
With a model selected and its model tab open click , , and then from the menu.
Tables, views, routines, routine groups, indexes, keys, and constraints can be imported from an SQL script file. Objects imported using an SQL script can be manipulated within MySQL Workbench the same as other objects. The following figure shows an example of the input and options available for this action.
Figure 9.46 Reverse Engineer SQL Script: Input
Select SQL script file: Open a file with the default file type set to an SQL script file, a file with the extension
sql.File encoding: Defaults to UTF8.
-
Place imported objects on a diagram: Also create an EER diagram in MySQL Workbench.
NoteImporting a large number (1000) objects could fail to create an EER diagram and instead emit a resource warning with the text "Too many objects are selected for auto placement. Select fewer elements to create the EER diagram." In this case, execute the reverse engineering wizard with this option disabled, manually create the EER diagram, and then import the 1000+ objects using the EER diagram catalog viewer.
If your script creates a database, MySQL Workbench creates a new Physical Schemas area within the open MySQL Model tab.
Click to reverse-engineer the SQL script, verify its results, and optionally place the objects in a new EER diagram. The next figure shows an example of the finished operation.
Figure 9.47 Reverse Engineer SQL Script: Execution
Click to view a summary of the results and then to close the wizard.
Figure 9.48 Reverse Engineer SQL Script: Results
Before exiting MySQL Workbench, save the schema. Click and then from the menu to save the reverse-engineered database as a MySQL Workbench file with the .mwb extension.
For a tutorial on reverse engineering the sakila database, see Section 9.3.3, “Importing a Data Definition SQL Script”.
Creating a DDL script
You can create a data definition (DDL) script by executing the mysqldump command. Using the db_name
--no-data >
script_file.sql--no-data option ensures that the script contains only DDL statements. However, if you are working with a script that also contains DML statements you need not remove them; they will be ignored.
If you plan to redesign a database within MySQL Workbench and then export the changes, be sure to retain a copy of the original DDL script. You will need the original script to create an ALTER script. For more information, see Section 9.4.1.1.2, “Altering a Schema”.
Use the --databases option with mysqldump if you wish to create the database as well as all its objects. If there is no CREATE DATABASE
statement in your script file, you must import the database objects into an existing schema or, if there is no schema, a new unnamed schema is created. db_name
© 2025 Oracle
Licensed under the GPLv2 License.
https://docs.oracle.com/cd/E17952_01/workbench-en/wb-reverse-engineer-create-script.html