|
| 1 | +# Exercise 8.3 - Relational Database |
| 2 | + |
| 3 | +Create a relational database container and create and access the case study database. |
| 4 | + |
| 5 | +### Step 1 |
| 6 | + |
| 7 | +Open the Cloud Platform Console at https://console.cloud.google.com. Go to Compute Engine and VM Instances. |
| 8 | +Start the VM if it isn’t running and connect using SSH. |
| 9 | + |
| 10 | +### Step 2 |
| 11 | + |
| 12 | +Change to the lab directory. |
| 13 | +`cd` |
| 14 | +`cd devops-lesson-8/lab-8.3` |
| 15 | + |
| 16 | +### Step 3 |
| 17 | + |
| 18 | +Initialize directory structure |
| 19 | + |
| 20 | +Create a Docker data volume to hold the database. |
| 21 | + |
| 22 | +`docker volume create --name monitoring_data` |
| 23 | + |
| 24 | +Confirm that the data volume was created. |
| 25 | + |
| 26 | +`docker volume ls` |
| 27 | + |
| 28 | +Examine the script that will run and create the scase study database structure. |
| 29 | + |
| 30 | +`cat runserver_first` |
| 31 | + |
| 32 | +Run the script to create a container with MySQL running and create the database. |
| 33 | + |
| 34 | +`./runserver_first` |
| 35 | + |
| 36 | +You will need to monitor the logs to see when MySQL has completed creating |
| 37 | +the student database and is waiting for connections. This may take several minutes |
| 38 | +to complete. |
| 39 | +`docker logs mysql` |
| 40 | + |
| 41 | +When you see the following in the logs you may continue. Run the command until you see. |
| 42 | + |
| 43 | +`mysqld: ready for connections.` |
| 44 | + |
| 45 | +Find the IP address of the server. |
| 46 | +`docker inspect mysql` |
| 47 | + |
| 48 | +### Step 4 |
| 49 | + |
| 50 | +Load data into the student database |
| 51 | + |
| 52 | +Examine the script that will run the MySQL client. Notice that we are using the same image. |
| 53 | +`cat runclient` |
| 54 | + |
| 55 | +Run the MySQL client container. |
| 56 | +`./runclient` |
| 57 | + |
| 58 | +You will be placed inside the client container running the Bash command shell. |
| 59 | +You can now type commands to use the database. You may need to change the IP address to that of the server. |
| 60 | +`mysql -h 172.17.0.2 -u student -p monitoring` |
| 61 | + |
| 62 | +You will be prompted for the password. Enter 'student' as the password |
| 63 | +`Enter password:` |
| 64 | + |
| 65 | +When you connect you will see the MySQL client prompt |
| 66 | +`mysql>` |
| 67 | + |
| 68 | +At the prompt read in the definition for the employee information. |
| 69 | +`mysql> source /data/docker.sql;` |
| 70 | + |
| 71 | +### Step 5 |
| 72 | + |
| 73 | +Examine the database tables in the database by selecting the first 10 rows from each |
| 74 | + |
| 75 | +`mysql> show tables;` |
| 76 | + |
| 77 | +Get the content of the docker table. |
| 78 | + |
| 79 | +`mysql> select * from docker;` |
| 80 | + |
| 81 | +Insert another row of data and query the table again. |
| 82 | + |
| 83 | +### Step 5 |
| 84 | + |
| 85 | +Clean up after the lab |
| 86 | + |
| 87 | + Exit from the MySQL client |
| 88 | +`mysql> quit;` |
| 89 | + |
| 90 | + Exit from the client container |
| 91 | + `exit` |
| 92 | + |
0 commit comments