Exercise 12: Setting up the Database

Let's go back to where we left off in the Exercise 11: Validating a Request of Chapter 2, Building the API – Part 1. In this example, we will be using MySQL as our database of choice. Make sure your machine is set up with MySQL and MySQL Workbench:


Use the Code/Lesson-3/exercise-a folder for your reference.
  1. Open MySQL Workbench. Click on the + button to create a connection:
  1. Add the connection name as packt, username as root, and the password (if any). Click on Test Connection to see if the connection is correct, then click on OK:
  1. Click on OK to create the connection.
  1. Now, click on the connection, packt:
  1. Create the todo database by running the following query, and click on the Execute icon:
CREATE DATABASE todo;
  1. The chapter files come with a basic SQL schema for our todo example project, almost similar to what we were using with the basic JavaScript array in the previous exercises:
    1. In the Code/Lesson-3 folder, there is a file called raw-sql.sql. Open the file with your code editor and copy the contents of the file.
    2. Then, go back to the MySQL Workbench.
    3. Paste what you copied from the file in the textbox and click on the Execute icon:
    1. You should see the list of the created tables (todo, todo_item, user) as below, when you click on the Refresh icon to the right of the SCHEMAS label, and click on Tables:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset