4.3. Adding Data to Your Database

In the previous section, you created a model, schema, and table. You also forward engineered your model to the live server. In this section, you will see how you can use MySQL Workbench to add data into your database on the live server.

  1. On the Home window, click the link Edit Table Data in the SQL Development area of the Workspace. This launches Edit Table Data wizard.

    Figure 4.19. Getting Started Tutorial - Edit Table Data

    Getting Started Tutorial - Edit Table Data

  2. In the wizard, select the Big Iron Server connection from the stored connection list. Click Next.

  3. Select the schema, dvd_collection. Select the table to edit, movies. Click Finish.

  4. You will see a data grid. This is where you can enter the data for your database. Remember that the movie_id was set to be autoincrement, so you need not enter values directly for this column. In the data grid, enter the movie information shown in the following table.

    titlerelease_date
    Gone with the Wind1939-04-17
    The Hound of the Baskervilles1939-03-31
    The Matrix1999-06-11
    Above the Law1988-04-08
    Note

    Do not modify any values in the movie_id column.

  5. Now click the Apply button in the toolbar located in the bottom right corner. A list of SQL statements will be displayed. Confirm that you understand the operations to be carried out. Click Apply to apply these changes to the live server.

  6. Confirm that the script was executed correctly, then click Finish.

  7. View the data grid again and observe that the autoincrement values have been generated.

    Figure 4.20. Getting Started Tutorial - Edit Data

    Getting Started Tutorial - Edit Data

  8. Now you will check that the data really has been applied to the live server. Launch the MySQL Command Line Client. Enter SELECT * FROM movies; to see the data just entered.

  9. You can also carry out a similar check from within MySQL Workbench. Click on the Home window tab.

  10. Click the link Open Connection to start Querying in the SQL Development section of the Workspace. This will launch the Connect to Database dialog. Select Big Iron Server from the list. Click OK.

  11. A new SQL Editor tab will be displayed. In the SQL Statements area, enter the following code:

    USE dvd_collection;
    SELECT * FROM movies;
  12. Now click the Execute toolbar button. This resembles a small lightning bolt. The SQL Editor will display a new Result tab contain the result of executing the SQL statements.

    Figure 4.21. Getting Started Tutorial - Results

    Getting Started Tutorial - Results

In this section of the tutorial, you have learned how to add data to your database, and also how to execute SQL statements using MySQL Workbench.