16.3.2. Creating a Model

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.

  1. Start MySQL Workbench. On the Home screen 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 simply delete it.

    Figure 16.12. Getting Started Tutorial - Home Screen

    Getting Started Tutorial - Home
              Screen
  2. 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. If at this stage you receive a message dialog asking to rename all schema occurrences, you can click Yes to apply your name change.

    Figure 16.13. Getting Started Tutorial - New Schema

    Getting Started Tutorial - New
              Schema
  3. In the Physical Schemata section double-click Add Table.

  4. Double-click table1 to launch the table editor (you may not have to do this as the table editor will automatically load at this point if you are using later versions of MySQL Workbench). In the table editor, change the name of the table to “movies” and press Enter.The table editor will then switch from the Table tab to the Columns tab, to allow you to enter details of your table columns.

  5. Change the name of the first column to “movie_id”. Select a data type of INT. You will then make this column have the following properties: primary key, not null, autoincrement. To do this click the PK, NN, and AI checkboxes.

  6. Add two further columns:

    Column NameData TypeColumn Properties
    movie_titleVARCHAR(45)NN
    release_dateDATE (YYYY-MM-DD)None.

    Figure 16.14. Getting Started Tutorial - Columns

    Getting Started Tutorial -
              Columns
  7. 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.

    Figure 16.15. Getting Started Tutorial - EER Diagram

    Getting Started Tutorial - EER
              Diagram
  8. Now, 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.

  9. At this point you can save your model. Click the main toolbar button Save Model to Current File. In this case 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.

  10. You can synchronize your model with the live database server. First you need to tell MySQL Workbench how to connect to the live server. From the main menu select Database, Manage Connections....

  11. In the Manage DB Connections dialog click New.

  12. Enter “Big Iron Server” for the connection name. This allows us to identify which server this connection corresponds to, although it is possible to create multiple connections to the same server.

  13. Enter the username for the account you will use to connect to the server.

  14. Click on the Store in Vault... button and enter the password for the username 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.

  15. Click Test Connection to test your connection parameters. If everything is OK at this point you can click Close.

    Figure 16.16. Getting Started Tutorial - Manage Connections

    Getting Started Tutorial - Manage
              Connections
  16. 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.

  17. The first page of the wizard is the Catalog Validation page. Click the Run Validations button to validate the Catalog. If everything is in order the wizard will report that validaton finished successfully. Click Next to continue.

  18. The Options page of the wizard shows various advanced options. For this tutorial you can ignore these and simply click Next.

  19. On the next page you can select the object you want to export to the live server. In this case we only have a table, so no other objects need to be selected. Click Next.

  20. The next screen, 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.

    Figure 16.17. Getting Started Tutorial - Review Script

    Getting Started Tutorial - Review
              Script
  21. Select the connection you created earlier, “Big Iron Server”. Click Execute. Check the messages for any erros, and then click Close to exit the wizard.

  22. Ensure that the script ran without error on the server and then click Close. As a simple test that the script worked launch the MySQL Command Line Client. 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 this previously.

  23. Ensure that your model is saved. Click Save Model to Current File on the main toolbar.

Copyright © 2010-2024 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout