Using MySQL Workbench you can reverse engineer a database using a MySQL create script or you can connect to a live MySQL server and import a single database or a number of databases. Reverse engineering using a MySQL DDL script applies to all versions of MySQL Workbench; reverse engineering a database directly from a MySQL server applies to commercial versions of MySQL Workbench only.
Reverse engineering using a create script is done by using the
sql
.
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 DDL statements only. 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 16.6.7.10.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
If your script creates a database, a new physical schemata tab is
created on the MySQL Model
page.
Any database objects may be imported from a script file in this fashion; tables, views, routines, and routine groups. Any indexes, keys, and constraints are also imported. Objects imported using an SQL script can be manipulated within MySQL Workbench in the same way that any other objects can.
Before exiting, be sure to save the schema. Choose the
mwb
.
See Section 16.6.8.1, “Importing a Data Definition SQL Script” for a tutorial on
reverse engineering the sakila
database.
This section explains how to reverse engineer a live database using MySQL Workbench.
Select the
, menu item from the main menu. Doing this opens the Reverse Engineer Database wizard.The first page of the wizard enables you to set up a connection to the live database you wish to reverse engineer. This enables you to set up a new connection, or select a previously created connection. Typical information required for the connection includes hostname, username and password.
Once this information has been entered, or you have selected a stored connection, click the
button to proceed to the next page:Review the displayed information to make sure that the connection did not generate errors, then click
.On the next page you can select the database schema you want to connect to among those available on the server. Simply click the checkbox or checkboxes associated with the schema you wish to process:
Once you have selected the desired schema, click the
button to continue.The wizard then displays the tasks it carried out and summarizes the results of the operation:
Review the results before clicking
to continue.
The next page is the Select Objects
page. It is
sectioned off by object type. This screen is of special interest
if you do not wish to import all the objects from the existing
database—this screen gives you the option of filtering which
objects are imported. Each section has a button. Click this button if you do not want to
import all the objects of a specific type.
For the Import MySQL Table Objects section, if you click the button the following page is displayed:
This enables you to select specific tables that you wish to import. Having selected the desired tables you can optionally hide the filter by clicking the
button.The other sections, such as MySQL Routine Objects, have similar filters available.
You can click
to continue to the next page.The wizard then displays the tasks that have been carried out and whether the operation was successful or not. If errors were generated then you can click the
button to see the nature of the errors.Click
to continue to the next page.The final screen of the wizard provides a summary of the reverse engineered objects:
Click
to exit the wizard.
Before exiting MySQL Workbench be sure to save the schema. Choose the
mwb
.
During reverse engineering the application checks for tables and views that duplicate existing names and disallows duplicate names if necessary. If you attempt to import an object that duplicates the name of an existing object you will be notified with an error message. To see any errors that have occurred during reverse engineering you can click the button
. This will create a panel containing a list of messages, including any error messages than may have been generated. Click the button to close the panel.If you wish to import an object with the same name as an existing object, rename the existing object before reverse engineering.
If you import objects from more than one schema, there will be a
tab in the Physical Schemata
section of the
MySQL Model
page for each schema imported.
You cannot reverse engineer a live database that has the same name as an existing schema. If you wish to do this, first rename the existing schema.