How to Create a Database from a Script in MySQL

To create a database from a script in MySQL:

  1. Open a Query tab in MySQL Workbench
  2. Run a CREATE DATABASE or CREATE SCHEMA statement to create the database (example below)

This will create a new database.

Screenshot of SQL script that creates a database in MySQL
Example of an SQL script that creates a database with tables, columns etc. In this case, the script has just run and has created the “Music” database. You can see the tables and their columns open in the left navigation pane.

Continue reading

How to Generate a Script from a Diagram in MySQL Workbench

To generate a script from a diagram in MySQL Workbench:

  1. Select File > Export > Forward Engineer SQL CREATE Script...
  2. Enter a location to save the file (optional) and set options to include on the script (such as DROP statements etc), then click Continue
  3. Exclude any objects by deselecting them, otherwise leave them as is, then click Continue
  4. The script is generated. You can copy it to your clipboard or click Finish to save it to a file

Continue reading

How to Create a New Database Diagram using MySQL Workbench

To create a new database diagram using MySQL Workbench:

  1. Click File > New Model from the menu
  2. Create a new schema by clicking the + icon next to Physical Schemas
  3. Add tables by clicking Add Tables, then add/configure their columns in the bottom pane.
  4. Create relationships and any other configurations by using the various tabs
  5. Create a diagram by clicking Model > Create Diagram from Catalog Objects

The diagram will be created. You can rearrange the tables to a more suitable layout by clicking and dragging.

Continue reading

What is MySQL Workbench?

MySQL Workbench is a graphical tool for working with MySQL.

MySQL Workbench provides an easy to use interface for performing the many tasks involved when working with databases. It integrates SQL development, administration, database design, creation and maintenance into one visual integrated development environment.

MySQL Workbench is similar to SQL Server’s SSMS, which is used for administering SQL Server.

Continue reading

How to Create a Database in MySQL Workbench using the GUI

To create a database in the MySQL Workbench GUI:

  1. Click the “new schema” button on the MySQL Workbench toolbar
  2. Enter a schema name (database name) and its default collation and click Apply
  3. Review the SQL statement and click Apply

The database will now be created, and a message will display advising that the script was successful.

Continue reading

How to Create a Table in MySQL Workbench using the GUI

To create a table in the MySQL Workbench GUI:

  1. Under the appropriate database in the left navigation pane, right-click Tables and select Create Table...
  2. Enter the table name, add all column names, their data type, constraints, default values, and any other details as required, then click Apply
  3. Review the SQL statement that will be run against the database and click Apply

The table will now be created, and a message will display advising that the script was successful.

Continue reading