How to Create MySQL Database in Workbench

October 17, 2024

Introduction

MySQL Workbench is a database management tool. It's open-source and provides a user-friendly cross-platform GUI for creating and editing MySQL databases.

This tutorial will show you how to create a MySQL database in Workbench. It also explains how to create a table and add data rows.

How to create a MySQL database in Workbench.

Prerequisites

Note: Learn how to check MySQL user privileges.

How to Create Databases in MySQL Workbench

MySQL Workbench automatically detects running MySQL server deployments on the local system, simplifying the database creation process. Follow the steps below to create a MySQL database using Workbench.

1. Open MySQL Workbench.

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

2. Select a database server in the MySQL Connections section.

Welcome to MySQL Workbench page and a MySQL server located in the MySQL Connections section.

When prompted, type the account password.

3. Click the database icon in the Workbench toolbar to start creating a database schema.

Locating the schema icon in MySQL Workbench to create a new schema.

Alternatively, select the Schemas tab in the window pane on the left side. Right-click anywhere in the blank area and select Create Schema from the menu.

Creating a new schema by right-clicking the schema section in MySQL Workbench.

4. Enter a name for the database. Allowed characters include letters, numbers, and the underscore (_). Optionally, choose the character set, such as Latin1 or UTF8.

The dialog for database creation in MySQL Workbench.

5. Click Apply when ready.

6. Review the SQL script that applies the changes to the database. If everything is in order, click Apply.

Reviewing the SQL Script to be applied to the Database in Workbench.

7. The output confirms that the SQL script successfully created a schema. Select Close to return to the main window.

Successful application of the SQL script to the database.

Bonus: How to Create Table in MySQL Workbench

After creating a database, use MySQL Workbench to add tables. The following section explains creating a table and adding data rows in Workbench.

1. Select the database in the Schemas tab located in the left-side pane.

2. Click the Create Table button in the Workbench toolbar.

Location of the Create Table button in the Workbench toolbar.

Alternatively, expand the database item in the pane, right-click the Tables item, and select Create Table.

Creating a table in Workbench using the menu on the left side.

3. Name the table in the Name field.

4. Double-click the empty section under the table name to add a column. Define the column name, data type, and any required constraints. Repeat the process for each new column.

Naming the table and creating columns.

5. Click Apply when done.

6. In the next dialog, review the script and select Apply. Select Close once the SQL script has been applied to the database.

Add Data to Table

After creating a table and defining its columns and data types, follow the steps below to learn how to add rows containing table data:

1. Locate the database in the left-side pane.

2. Expand the Tables item.

3. Hover the cursor over the table you want to modify. Three icons appear on the right side of the table name. Select the rightmost icon to load the table.

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

A new window opens. The top section shows MySQL statements, while the bottom section shows the data rows. The example below shows the table with NULL values.

The window showing a table with NULL values.

4. Double-click the row and type values in each column. Once you entered the data, click the Apply button.

A sample table with three data rows.

5. A new window with the SQL script appears. Review the script and select Apply. In the next window, select Close to finish adding the data.

Conclusion

By following the steps in this tutorial, you have successfully created a MySQL database and table in Workbench. Additionally, the article taught you how to add data to your tables.

Next, learn how to start, stop, and restart a MySQL server via the command line and GUI.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
MySQL Performance Tuning and Optimization Tips
December 12, 2018

This guide provides several tuning tips on improving a MySQL database's performance...
Read more
Install and Get Started with MySQL Workbench on Ubuntu
October 17, 2024

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

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