workbench-en.a4
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 4. MySQL Workb<strong>en</strong>ch Tutorials<br />
This chapter contains three short tutorials int<strong>en</strong>ded to familiarize you with the basics of MySQL Workb<strong>en</strong>ch. These tutorials show<br />
how MySQL Workb<strong>en</strong>ch can be used both to design and to docum<strong>en</strong>t databases.<br />
Creating a database from scratch is the focus of Section 4.2, “Using the Default Schema” and exploring the graphic design capabilities<br />
of MySQL Workb<strong>en</strong>ch is touched upon in Section 4.3, “Basic Modeling”. Both these tutorials show the database design capabilities<br />
of MySQL Workb<strong>en</strong>ch<br />
Importing an SQL data definition script is probably the quickest way to familiarize yourself with MySQL Workb<strong>en</strong>ch — this tutorial<br />
makes use of the sakila database and emphasizes the use of MySQL Workb<strong>en</strong>ch as a docum<strong>en</strong>tation tool. Examples tak<strong>en</strong><br />
from the sakila database are used throughout the docum<strong>en</strong>tation so doing this tutorial can be very helpful in understanding MySQL<br />
Workb<strong>en</strong>ch.<br />
4.1. Importing a Data Definition SQL Script<br />
For this tutorial use the sakila database script found in the Example Databases section of the http://dev.mysql.com/doc/<br />
page.<br />
After downloading the file, extract it to a conv<strong>en</strong>i<strong>en</strong>t location. Op<strong>en</strong> MySQL Workb<strong>en</strong>ch and find the REVERSE ENGINEER MYSQL<br />
CREATE SCRIPT m<strong>en</strong>u option by first selecting FILE and th<strong>en</strong> IMPORT. Find and import the sakila-schema.sql file. This is the<br />
script that contains the data definition statem<strong>en</strong>ts for the sakila database. The file filter for the file op<strong>en</strong> dialog window defaults<br />
to *.sql so you should only be able to view files with the sql ext<strong>en</strong>sion.<br />
If the file was successfully imported, the application's status bar reads, Import MySQL Create Script done. To view the<br />
newly imported script, expand the Physical Schemata section by double clicking the arrow on the left of the Physical<br />
Schemata title bar. Select the tab labelled SAKILA.<br />
Yo may also wish to remove the default schema tab, mydb. Do this by selecting this tab and th<strong>en</strong> clicking the - button on the upper<br />
right in the PHYSICAL SCHEMATA panel.<br />
To view all the objects in the sakila schema, you may need to expand the PHYSICAL SCHEMATA window. To do this move the<br />
mouse pointer anywhere over the gray area that defines the lower edge of the PHYSICAL SCHEMATA window. Hold down the right<br />
mouse button and move the mouse to adjust the size of the window.<br />
Once you've expanded the window, all the objects in the sakila database should be visible. Tables appear at the top followed by<br />
views and th<strong>en</strong> routines. There are no routine groups in this schema, but you should see the ROUTINE GROUPS section and an Add<br />
Group icon.<br />
For a complete description of importing a MySQL create script see Section 15.1, “Reverse Engineering Using a Create Script”.<br />
4.1.1. Adding an EER Diagram<br />
To create an EER diagram for the sakila database, first add an EER diagram by double clicking the Add Diagram icon in the<br />
EER DIAGRAMS panel. This should create and op<strong>en</strong> a new EER Diagram.<br />
The EER Diagram canvas is where object modeling takes place. To add a table to the canvas, select the CATALOG tab in the<br />
middle panel on the right side of the application. This should display any schemata that appear in the MYSQL MODEL tab.<br />
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<br />
list in the same way.<br />
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<br />
table and the city table onto the canvas.<br />
Figure 4.1. Adding tables to the canvas<br />
5