{"id":796,"date":"2017-10-09T12:34:34","date_gmt":"2017-10-09T12:34:34","guid":{"rendered":"http:\/\/technicalelvis.com\/blog\/?p=796"},"modified":"2022-08-21T16:21:29","modified_gmt":"2022-08-21T16:21:29","slug":"data-101-mysql-tutorial-using-diabetes-database","status":"publish","type":"post","link":"https:\/\/technicalelvis.com\/blog\/2017\/10\/09\/data-101-mysql-tutorial-using-diabetes-database\/","title":{"rendered":"Data 101: MySQL Tutorial using a Diabetes Database"},"content":{"rendered":"<h1>Introduction<\/h1>\n<p>This tutorial demonstrates how to use MySQL and MySQL Workbench to create and explore a MYSQL database containing diabetes treatment records.<\/p>\n<h2>Original Dataset<\/h2>\n<p>I generated the SQL for this tutorial using the <a href=\"https:\/\/archive.ics.uci.edu\/ml\/datasets\/diabetes\">Diabetes Data Set from the UCI Machine Learning Repository<\/a>. I added a \"patients\" table using random celebrity names.<\/p>\n<h1>MySQL Setup<\/h1>\n<ul>\n<li>The raw data for the tutorial is on <a href=\"https:\/\/github.com\/telvis07\/book-data-by-example\/tree\/master\/medical_databases\/sql\">my github here<\/a>.<\/li>\n<li>MySQL Installer :\u00a0<a href=\"https:\/\/dev.mysql.com\/downloads\/mysql\/\">https:\/\/dev.mysql.com\/downloads\/mysql\/<\/a><\/li>\n<li>MySQL Workbench Installer :\u00a0<a href=\"https:\/\/dev.mysql.com\/downloads\/workbench\/\">https:\/\/dev.mysql.com\/downloads\/workbench\/<\/a><\/li>\n<\/ul>\n<h2>Connecting to the Database<\/h2>\n<p><span style=\"font-weight: 400;\">Open MySQL Workbench. Click Database -&gt; Connect to Database<\/span><\/p>\n<figure id=\"attachment_798\" aria-describedby=\"caption-attachment-798\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-798\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_database-300x174.png\" alt=\"Connect to a MySQL Database Menue\" width=\"300\" height=\"174\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_database-300x174.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_database-624x363.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_database.png 740w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-798\" class=\"wp-caption-text\">Connect to a MySQL Database via Menu<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">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 \u201cPassword\u201d to enter the password generated during installation.<\/span><\/p>\n<figure id=\"attachment_799\" aria-describedby=\"caption-attachment-799\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-799\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_db_ip_password-300x129.png\" alt=\"Enter IP and Password for MySQL database.\" width=\"300\" height=\"129\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_db_ip_password-300x129.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_db_ip_password-768x330.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_db_ip_password-1024x440.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_db_ip_password-624x268.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_connect_to_db_ip_password.png 1372w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-799\" class=\"wp-caption-text\">Enter IP and Password for MySQL database.<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Save the password here:<\/span><\/p>\n<figure id=\"attachment_800\" aria-describedby=\"caption-attachment-800\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-800\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_save_password-300x158.png\" alt=\"Save your password (MacOS)\" width=\"300\" height=\"158\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_save_password-300x158.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_save_password-768x405.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_save_password-624x329.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_save_password.png 830w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-800\" class=\"wp-caption-text\">Save your password (MacOS)<\/figcaption><\/figure>\n<p>Now that you connected to the server, list the installed databases using.<\/p>\n<pre><code class=\"mysql\">SHOW SCHEMAS<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">You should see the following output similar to this:<\/span><\/p>\n<figure id=\"attachment_804\" aria-describedby=\"caption-attachment-804\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-804\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_show_schema-300x92.png\" alt=\"MySQL Workbench Output of Show Schema\" width=\"300\" height=\"92\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_show_schema-300x92.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_show_schema-768x236.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_show_schema-1024x315.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_show_schema-624x192.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_show_schema.png 1898w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-804\" class=\"wp-caption-text\">MySQL Workbench Output of Show Schema<\/figcaption><\/figure>\n<h2><span style=\"font-weight: 400;\">Creating the Diabetes Database<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In MySQL workbench, execute \u201ccreate_diabetes_db.sql\u201d using \u201cFile -&gt; Open SQL Script\u201d.<\/span><\/p>\n<figure id=\"attachment_806\" aria-describedby=\"caption-attachment-806\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-806\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_sql_script-300x161.png\" alt=\"&quot;Open SQL Script&quot; Menu\" width=\"300\" height=\"161\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_sql_script-300x161.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_sql_script-768x411.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_sql_script-624x334.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_sql_script.png 968w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-806\" class=\"wp-caption-text\">\"Open SQL Script\" Menu<\/figcaption><\/figure>\n<p>You can find this file in my github within the <a href=\"https:\/\/github.com\/telvis07\/book-data-by-example\/blob\/master\/medical_databases\/sql\/create_diabetes_db.sql\">medical_databases\/sql\/ directory<\/a>.<\/p>\n<figure id=\"attachment_808\" aria-describedby=\"caption-attachment-808\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-808\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_create_diabetes_db_sql-300x110.png\" alt=\"Open &quot;create_diabetes_db.sql&quot;\" width=\"300\" height=\"110\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_create_diabetes_db_sql-300x110.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_create_diabetes_db_sql-768x282.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_create_diabetes_db_sql-624x229.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_create_diabetes_db_sql.png 1018w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-808\" class=\"wp-caption-text\">Open \"create_diabetes_db.sql\"<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Once the file is open, use Command-A to \u201cSelect ALL\u201d - or (Edit -&gt; Select ALL).<\/span><\/p>\n<figure id=\"attachment_809\" aria-describedby=\"caption-attachment-809\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-809\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_create_diabetes_sql-300x220.png\" alt=\"&quot;Select All&quot; SQL in window\" width=\"300\" height=\"220\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_create_diabetes_sql-300x220.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_create_diabetes_sql-768x562.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_create_diabetes_sql-1024x750.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_create_diabetes_sql-624x457.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_create_diabetes_sql.png 1172w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-809\" class=\"wp-caption-text\">\"Select All\" SQL in window<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Now Click the Execute (leftmost lightning bolt) button. The \u201cAction Output\u201d window should show:<\/span><\/p>\n<figure id=\"attachment_810\" aria-describedby=\"caption-attachment-810\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-810\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_create_db_output_window-300x20.png\" alt=\"Output from &quot;create db&quot; script\" width=\"300\" height=\"20\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_create_db_output_window-300x20.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_create_db_output_window-768x52.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_create_db_output_window-1024x70.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_create_db_output_window-624x42.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_create_db_output_window.png 1880w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-810\" class=\"wp-caption-text\">Output from \"create db\" script<\/figcaption><\/figure>\n<h2><span style=\"font-weight: 400;\">Loading the Diabetes Data into the Database<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Now open \u201cdiabetes_data.sql\u201d. <a href=\"https:\/\/github.com\/telvis07\/book-data-by-example\/blob\/master\/medical_databases\/sql\/diabetes_data.sql\">Click here to download that file from github<\/a>.<\/span><\/p>\n<figure id=\"attachment_811\" aria-describedby=\"caption-attachment-811\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-811\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_diabetes_data_sql-300x92.png\" alt=\"Open &quot;diabetes_data.sql&quot;\" width=\"300\" height=\"92\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_diabetes_data_sql-300x92.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_diabetes_data_sql-768x234.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_diabetes_data_sql-1024x312.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_diabetes_data_sql-624x190.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_open_diabetes_data_sql.png 1036w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-811\" class=\"wp-caption-text\">Open \"diabetes_data.sql\"<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Once the file is open, use Command-A to \u201cSelect ALL\u201d - or (Edit -&gt; Select ALL). This is a big file so you\u2019ll only see the beginning part in the window.<\/span><\/p>\n<figure id=\"attachment_812\" aria-describedby=\"caption-attachment-812\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-812\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_diabetes_data_sql-300x212.png\" alt=\"&quot;Select All&quot; Diabetes data SQL\" width=\"300\" height=\"212\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_diabetes_data_sql-300x212.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_diabetes_data_sql-768x543.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_diabetes_data_sql-1024x724.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_diabetes_data_sql-624x441.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_all_diabetes_data_sql.png 1596w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-812\" class=\"wp-caption-text\">\"Select All\" Diabetes data SQL<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Now Click the Execute button (leftmost lightning bolt). The \u201cAction Output\u201d window should show something similar to the output below. There are lot of commands in this file but you should see some \u201cCREATE TABLE\u201d and \u201cINSERTS\u201d statements.<\/span><\/p>\n<figure id=\"attachment_813\" aria-describedby=\"caption-attachment-813\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-813\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_ouput_diabetes_data_sql-300x28.png\" alt=\"Output from executing diabetes data SQL\" width=\"300\" height=\"28\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_ouput_diabetes_data_sql-300x28.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_ouput_diabetes_data_sql-768x71.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_ouput_diabetes_data_sql-1024x95.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_ouput_diabetes_data_sql-624x58.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_ouput_diabetes_data_sql.png 1854w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-813\" class=\"wp-caption-text\">Output from executing diabetes data SQL<\/figcaption><\/figure>\n<p><span style=\"font-weight: 400;\">Now create a new \u201cQuery Tab\u201d. (File -&gt; New Query Tab) or COMMAND-T then try the query:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">SELECT * FROM patients;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">The result grid pane should show something similar to the following.<\/span><\/p>\n<figure id=\"attachment_814\" aria-describedby=\"caption-attachment-814\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-814\" src=\"http:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_star_from_patients-300x62.png\" alt=\"&quot;SELECT * FROM patients&quot; Output\" width=\"300\" height=\"62\" srcset=\"https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_star_from_patients-300x62.png 300w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_star_from_patients-768x159.png 768w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_star_from_patients-1024x212.png 1024w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_star_from_patients-624x129.png 624w, https:\/\/technicalelvis.com\/blog\/wp-content\/uploads\/2017\/10\/workbench_select_star_from_patients.png 1900w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-814\" class=\"wp-caption-text\">\"SELECT * FROM patients\" Output<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;patients&#8221; table using random celebrity names. MySQL Setup The raw &hellip; <a href=\"https:\/\/technicalelvis.com\/blog\/2017\/10\/09\/data-101-mysql-tutorial-using-diabetes-database\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Data 101: MySQL Tutorial using a Diabetes Database<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[21,20],"tags":[],"class_list":["post-796","post","type-post","status-publish","format-standard","hentry","category-data_101","category-datums"],"_links":{"self":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts\/796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/comments?post=796"}],"version-history":[{"count":13,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts\/796\/revisions"}],"predecessor-version":[{"id":882,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/posts\/796\/revisions\/882"}],"wp:attachment":[{"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/media?parent=796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/categories?post=796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/technicalelvis.com\/blog\/wp-json\/wp\/v2\/tags?post=796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}