Creating a Database Schema in MySQL Workbench
This guide teaches you how to create a database schema in MySQL Workbench. A schema is a tool we can use to wrap all of our database tables inside.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Now that we have MySQL installed and we've configured MySQL workbench. We can start creating what we need to do in order to go through the course. So if you open up MySQL workbench and double click on the SQL connection that you made. I'm going to use the new connection that I created in the last guide. double click on the connection.

large

On the left-hand side, we already walked through the server status. We're going to walk through how we can create a database schema. A schema is a workspace for our database that allows us to group all of our data together. A database is going to be made up of all kinds of tables that are in different places. We are able to store data that relates to other tables in our schema. It's a way where we can define where our tables exist and how they relate to one another. You can see the schema’s on the left-hand side. There's some sample data here; this is from a few test databases that I have on my system. We're going to go through what we need to do in order to create one from scratch.

So if you come up here to the top left-hand corner of MySQL workbench, you can see that if I hover over the button it says “create a new schema in the connected server.”

large

Click on the button and it will pop open this dialog box in a new tab. Now fill in the schema name. I am going to name this is the devcamp_sql_course_schema. You can name yours anything you like. You don't have to make any other changes besides giving the schema a name.

Now if I click on “apply” this is going to pop up a box that says “Review the SQL script to be applied to the database”. This is one of the really nice features of using a tool like MySQL workbench. if you're not that familiar SQL, MySQL workbench will actually create a decent amount the SQL code for you. It will then show you exactly what's been created. Without this, we'd have to write all of this from scratch in the terminal. If that's not something that you want to do then this is a great option.

large

So right here it's a single command on a single line and it's going to say ’CREATE SCHEMA devcamp_sql_course_schema’ ;. So what this is going to do is give us our names pacing and our grouping that can store all of our tables inside. Press “apply” and it says “SQL statement was successfully applied to the database.”

large

Doing it this way would be the exact same as if we went in the terminal, opened up a connection to MySQL, and ran then that schema creator. So that's I want you to kind of keep in mind that all of these things whether you see someone do it in the command line or you see it in MySQL workbench, they're pretty much all the same.

MySQL workbench is simply giving commands to the system so that it can understand what we're wanting to do. In this case, we want it to create a database schema for us. So now when I click close, you can see the schema here on the left-hand side. We can now see the "devcamp_sql_course_schema" schema. If your schema name is too long you can grab the bar next to it and drag it out.

medium

Now if I click on the ‘devcamp_sql_course_schema’ it will show tables, views, stored procedures, and functions. If I click on ‘table’ there won't be any tables because we haven't created those yet. We're going to do that in the next few guides! If I click on one of these other schemas I have on my computer. For instance, If I click on “sample_two” and then click on the “tables” it will drop down all the tables for that schema. Such as addresses, friends, guides, and users. They all have data inside of them so we could see the columns, indexes, foreign keys, and anything like that.

medium

So this is a really helpful tool for being able to navigate inside of a database and see the structure. We're going to build all of this from scratch as we go through the course. So that is how you can build a database schema and in the next guide, we're going to talk about how we can actually go through and create our first table.