For this tutorial use the sakila
database
script found in the Example Databases
section
of the http://dev.mysql.com/doc/ page.
After downloading the file, extract it to a convenient location.
Open MySQL Workbench and find the sakila-schema.sql
file. This
is the script that contains the data definition statements for the
sakila
database. The file filter for the file
open dialog window defaults to *.sql
so you
should only be able to view files with the sql
extension.
If the file was successfully imported, the application's status
bar reads, Import MySQL Create Script done.
To
view the newly imported script, expand the Physical
Schemata
section by double-clicking the arrow on the
left of the Physical Schemata
title bar. Select
the tab labelled sakila.
Yo may also wish to remove the default schema tab,
mydb
. Do this by selecting this tab and then
clicking the button on the upper right in
the Physical Schemata panel.
To view all the objects in the sakila
schema,
you may need to expand the Physical Schemata
window. To do this move the mouse pointer anywhere over the gray
area that defines the lower edge of the Physical
Schemata window. Hold down the right mouse button and
move the mouse to adjust the size of the window.
Once you've expanded the window, all the objects in the
sakila
database should be visible. Tables
appear at the top followed by views and then routines. There are
no routine groups in this schema, but you should see the
Routine Groups section and an Add
Group
icon.
For a complete description of importing a MySQL create script see Section 16.6.7.9.1, “Reverse Engineering Using a Create Script”.
To create an EER diagram for the sakila
database, first add an EER diagram by double-clicking the
Add Diagram
icon in the EER
Diagrams panel. This should create and open a new
EER Diagram
.
The EER Diagram
canvas is where object
modeling takes place. To add a table to the canvas, select the
Catalog tab in the middle panel on the
right side of the application. This should display any schemata
that appear in the MySQL Model tab.
Find the sakila schema and expand the view of its objects by clicking the
button to the left of the schema name. Expand the tables list in the same way.
You can add tables to the EER canvas by picking them up from the
Catalog panel and placing them on the
canvas. Drop the address
table and the
city
table onto the canvas.
MySQL Workbench automatically discovers that
address.city_id
has been defined as a foreign
key referencing the city.city_id
field. Drop
the country
table onto the canvas and
immediately you should see the relationship between the
country
table and the city
table. ( See Figure 16.82, “The sakila
EER Diagram” to view a PNG
file of all the relationships in the sakila
database.)
Choose the Properties
tab of the panel on the
lower right and then click one of the tables on the canvas. This
displays the properties of the table in the
Properties
window. While a table is selected
you can use the Properties
window to change a
table's properties. For example, entering
#FF0000
for the color value will change the
color accent to red.
Changing the color of a table is a good way to identify a table
quickly—something that becomes more important as the
number of tables increases. Changing the color of a table is
also an easy way to identify a table in the Model
Navigator
panel. This panel, the uppermost panel on
the left side of the screen, gives a bird's eye view of the
entire EER canvas.
Save your changes to a MySQL Workbench Models
file (mwb) by choosing from the
menu or by using the keyboard command
Ctrl S.