How to Create MySQL Database in Workbench

January 29, 2020

Introduction

Workbench is a cross-platform, open-source, visual tool for database management.

While some database architects and administrators like working via command line, others prefer a GUI. Workbench provides a user-friendly GUI in which you can create and maintain databases.

Learn how to create a MySQL database and table in Workbench, as well as how to add data to a table.

Tutorial on how to create a MySQL databae in Workbench.

Prerequisites

  • MySQL Workbench installed on your system
  • A MySQL server (as Workbench works with MySQL databases)

Note: If you are using Ubuntu and don’t have Workbench set up yet, refer to our article on how to install MySQL Workbench on Ubuntu 18.04.

How to Use MySQL Workbench to Create a Database

1. To create a database, you first need to open Workbench.

2. Choose the database server you have access to and connect to it.

3. There are two ways to create a new database:

  • Locate the Schema section in the sidebar on the left side and right-click the white (blank) area. Click Create Schema. The schema you create is, in fact, a database.
Righ-click the schema section in MySQL Workbench to create a new schema.
  • Click the icon for creating a new schema in the Workbench toolbar.
Click the schema icon in MySQL Workbench to create a new schema.

4. Name the database, stick to alpha-numerical characters, and replace spaces with an underscore ( _ ).

5. You can set the default collation, such as Latin1 or UTF8. However, it is not mandatory. If you do not define the collation, it automatically uses what is assigned to the server instance.

6. Click Apply. Workbench lets you revise the SQL script that will be applied to the database. If everything is in order, click Apply once more.

Review the SQL Script to be applied to the Database in Workbench and click Apply.

Note: Make sure the statements you are about to apply work for your database. Once you commit to the SQL script, you won’t be able to revert the statements without losing some data.

7. Next, the output will inform you that the SQL script was successfully applied to the database.

8. With this step, you have created a database (schema). Close the SQL script and start working on your table.

Create a Table

Just like the database, you can create a table using the Workbench GUI.

1. Expand the database in which you want to create a table.

2. The first item in the expanded menu should be Tables. Right-click the item and select Create Table.

Create a table in Workbench

3. Give your table a name.

4. Double-click the empty white section under the table name to add columns.

5. Define the column name, data type, and any constraints it may require.

6. Add as many columns you need, and then select Apply.

With that, you have executed the SQL script, and you can move on to adding data to the table.

Add Data to Table

There are a few steps you need to take before you can add data to your table.

1. In the left sidebar, locate the table to which you want to add data.

2. Hover the mouse over the table. Three (3) light gray icons appear on the right side. The last one is the table icon. Click that little table icon to load the table.

Hover over the table name in Workbench to reveal the icons.


3. This action prompts a new window in which the upper left section shows the MySQL statement, while the lower section shows the data rows (currently with null values).

4. To add data rows, select the respected column, and type the value. Once you entered the data, click the Apply button.

5. A new window with the SQL script appears. Click Apply and Finish to add the data.

Conclusion

You have successfully created a MySQL database and table in Workbench. In addition, you have learned how to add data to your tables, and you can now start working with different MySQL databases.

Check out our guide on how to create a table in MySQL and insert data, as well as different ways to query the data using MySQL shell or File Script.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Install MySQL 8.0 in Ubuntu 18.04
December 12, 2018

MySQL is an open-source relational database server tool for Linux operating systems. It is widely used in...
Read more
Install and Get Started with MySQL Workbench on Ubuntu 18.04
January 29, 2020

Workbench is a visual tool for managing MySQL databases . Its graphical interface allows administrators and...
Read more
How to Fix 'MySQL Command Not Found'
December 11, 2019

The 'Command Not Found' error is a general error not only found in MYSQL. By learning how to deal with...
Read more
PostgreSQL Vs MySQL: A Detailed Comparison
March 30, 2023

Explore the differences between the two most widely used database management systems. PostgreSQL and MySQL...
Read more