Introduction
This tutorial demonstrates how to use MySQL and MySQL Workbench to create and explore a MYSQL database containing diabetes treatment records.
Original Dataset
I generated the SQL for this tutorial using the Diabetes Data Set from the UCI Machine Learning Repository. I added a "patients" table using random celebrity names.
MySQL Setup
- The raw data for the tutorial is on my github here.
- MySQL Installer : https://dev.mysql.com/downloads/mysql/
- MySQL Workbench Installer : https://dev.mysql.com/downloads/workbench/
Connecting to the Database
Open MySQL Workbench. Click Database -> Connect to Database
The local MySQL server should be running on Hostname: 127.0.0.1 and Port 3306. Your hostname or IP address may be different if you are connecting to another host running MySQL. Click on “Password” to enter the password generated during installation.
Save the password here:
Now that you connected to the server, list the installed databases using.
SHOW SCHEMAS
You should see the following output similar to this:
Creating the Diabetes Database
In MySQL workbench, execute “create_diabetes_db.sql” using “File -> Open SQL Script”.
You can find this file in my github within the medical_databases/sql/ directory.
Once the file is open, use Command-A to “Select ALL” - or (Edit -> Select ALL).
Now Click the Execute (leftmost lightning bolt) button. The “Action Output” window should show:
Loading the Diabetes Data into the Database
Now open “diabetes_data.sql”. Click here to download that file from github.
Once the file is open, use Command-A to “Select ALL” - or (Edit -> Select ALL). This is a big file so you’ll only see the beginning part in the window.
Now Click the Execute button (leftmost lightning bolt). The “Action Output” window should show something similar to the output below. There are lot of commands in this file but you should see some “CREATE TABLE” and “INSERTS” statements.
Now create a new “Query Tab”. (File -> New Query Tab) or COMMAND-T then try the query:
SELECT * FROM patients;
The result grid pane should show something similar to the following.