How to Create MySQL Database in Workbench

By
Marko Aleksic
Published:
October 17, 2024
Topics:

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