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.
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.
- Click the icon for creating a new schema in the Workbench toolbar.
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.
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.
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.
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.
原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/226172.html