Create a Database using MySQL Workbench
Create a Database using MySQL Workbench
You can use the MySQL Workbench GUI to create a database. You can also create a database programmatically but here's how to do it via the GUI.
In the following example, we create a new database called "VegeShop".
- Click the icon for creating a new schema (you'll find this on the Workbench toolbar):
- Enter the schema name (in this case, VegeShop) and the default collation (in this case, latin1 - default collation), then click the Apply button:
- You are prompted to review the SQL statement that will be run to create the database. To run the statement (and create the database) click Apply:
- You should see the following screen once the database has been created:
The database has now been created. You will now see your new database listed under the SCHEMAS tab on the left pane:
Setting the Default Database
You can set the new database as the default database by right-clicking on it and selecting Set as Default Schema:
You can tell when a database is the default database because its name is rendered in a bold typeface:
Creating Databases Programatically
As mentioned, you can also create your databases programmatically. This is as quick and easy as writing CREATE DATABASE VegeShop. You can also add code that checks for the existence of any databases that already use that name.
Create the Tables
The above database is an empty database. It doesn't have any tables yet. As with creating your database, you can create your tables either programmatically or via the GUI.