In this section, you will learn how to create a new database model, create a table, create an EER Diagram of your model, and then forward engineer your model to the live database server.
Start MySQL Workbench. On the Home window, select Create
new EER Model. A model can contain multiple
schemata. Note that when you create a new model, it contains
the mydb schema by default. You can change
the name of this schema to serve your own purposes, or delete
it.
On the Physical Schemata toolbar, click the button + to add a new schema. This will create a new schema and display a tabsheet for the schema. In the tabsheet, change the name of the schema to “dvd_collection”, by typing into the field called Name. Ensure that this change is reflected on the Physical Schemata tab. Now you are ready to add a table to your schema.
In the Physical Schemata section, double-click Add Table.
This will automatically load the table editor, with the default table name being table1. In the table editor, change the name of the table from “table1” to “movies”.
Next, add several columns. Double click a cell within the
Column Name column, and the first field
will default to “moviesid” because MySQL Workbench
appends “id” to the table name as the default for
the initial field. Change the name to “movie_id”
and keep the Datatype as
INT. Then, be sure PK
(PRIMARY KEY), NN (NOT NULL), and
AI (AUTO_INCREMENT) are all checked.
Add two additional columns using the same method as described above:
| Column Name | Data Type | Column Properties |
|---|---|---|
| movie_title | VARCHAR(45) | NN |
| release_date | DATE (YYYY-MM-DD) | None |
Now you can obtain a visual representation of this schema so far. From the main menu, select Model, Create Diagram from Catalog Objects. The EER Diagram will be created and displayed.
In the table editor, change the name of the column “movie_title” to “title”. Note that the EER Diagram is automatically updated to reflect this change.
At this point, you can save your model. Click the main toolbar
button Save Model to Current File. You
have not yet saved this file so you will be prompted to enter
a model file name. For this tutorial, enter
“Home_Media”. The Home_Media model may contain
further schemata in addition to
dvd_collection, such as
cd_collection. Click
Save to save the model.
You can synchronize your model with the live database server. First, you must tell MySQL Workbench how to connect to the live server. From the main menu, select Database, Manage Connections....
In the Manage DB Connections dialog, click New.
Enter “Big Iron Server” for the connection name. This enables you to identify the server to which this connection corresponds, although it is possible to create multiple connections to the same server.
Enter the user name for the account you will use to connect to the server.
Click on the Store in Vault... button and enter the password for the user name you entered in the previous step. You can optionally ignore this step, and you will be prompted for this password whenever MySQL Workbench connects to the server.
Click Test Connection to test your connection parameters. If everything is okay at this point, you can click Close.
You are now ready to forward engineer your model to the live server. From the main menu, select Database, Forward Engineer.... The Forward Engineer to Database wizard will be displayed.
The Options page of the wizard shows various advanced options. For this tutorial, you can ignore these and simply click Next.
On the next page, you can select the object you want to export to the live server. In this case, you only have a table, so no other objects need be selected. Click Next.
The next page, Review SQL Script, displays the script that will be run on the live server to create your schema. Review the script to make sure that you understand the operations that will be carried out. Click Next.
Select the connection you created earlier, “Big Iron Server”. Click Execute. Check the messages for any errors, then click Close to exit the wizard.
Ensure that the script ran without error on the server, then
click Close. As a simple test that the
script worked launch the MySQL Command Line Client
(mysql). Enter SHOW
DATABASES; and identify your schema. Enter
USE dvd_collection; to select your schema.
Now enter SHOW TABLES;. Enter
SELECT * FROM movies;, this will return the
empty set as you have not yet entered any data into your
database. Note that it is possible to use MySQL Workbench to carry
out such checks, and you will see how to do this later, but
the MySQL Command Line Client has been used here as you have
probably used it previously.
Ensure that your model is saved. Click Save Model to Current File on the main toolbar.

User Comments
Add your own comment.