MySQL Create Database Statement

The MySQL CREATE DATABASE statement is used to create a new database. It allows you to specify the database name and optional settings, such as character set and collation, ensuring the database is ready for storing and managing data.

In this article, we are going to learn how we can create databases in the MySQL database management system through the command line client tool and the MySQL Workbench application. We will provide a step-by-step tutorial to create databases in both of these applications.

  • Command Line Client
  • MySQL Workbench application

MySQL Command Line Client

The MySQL Command Line Client allows you to create a database using the CREATE DATABASE statement. By entering SQL commands directly, users can efficiently manage databases, tables, and data, making it a powerful tool for database administration.

Syntax:

CREATE DATABASE [IF NOT EXISTS] Nameof_database

[CHARACTER SET Nameof_charset]

[COLLATE Nameof_Collation];

Parameters:

  • Nameof_database: The name of the database to be created.
  • IF NOT EXISTS: Optional; checks if a database with the same name already exists to prevent an error.
  • Nameof_charset: Optional; specifies the character set for the database.
  • Nameof_Collation: Optional; specifies the collation for the database.

How to Create a Database Using the MySQL Command Line Client

The command line client comes as a default tool when you install MySQL on your system. You can follow this article if you want a step-by-step guide to installing MYSQL on your systems.

The MYSQL command line client is a command line interface that allows the users to directly interact with the MYSQL database server directly through the command. It provides a text-based environment to the users for executing the SQL queries directly and allows the users to manage their databases as well. To create a database through the MYSQL command line client follows the below steps:

1. Search for MYSQL Command line Client at the start.

2. Open the application and then Enter your password.

3. Run the following command to check the existing databases in the system.

SHOW DATABASES;

Output:

All databases present in the system

4. After that run the following command to create a database of your choice.

CREATE DATABASE IF NOT EXISTS DATABASE_NAME

Output:

If you see the following output then you can ensure that your database was successfully created.

5. Again run the SHOW Databases command and you will see your database is created.

Output:

6. Run the following command to use the database you have just created.

USE DATABASE_NAME;

MySQL Workbench

The MySQL Workbench is a visual database design and management tool that provides a GUI for interacting with MySQL databases. It is suitable for users who prefer a visual interface over a command-line tool.

How to Create Database Using the MySQL Workbench Application

You can follow this article if you want to install MYSQL Workbench on your systems.

The MySQL Workbench is a visual database design and management tool that provides a user-friendly Graphical user interface(GUI) to the users through which they can interact with the MySQL database directly. This application is beneficial for those users who prefer a visual approach to the development of databases rather than command-line interfaces. To create a database through MySQL Workbench follow the below steps:

1. Search for MySQL workbench in start.

2. Click on the following icon to create a local instance for your database.

3. Enter Local as your connection name and click on the Test connection button.

4. Enter your Password. The password should be the same one you set during the MYSQL installation.

5. If the connection was successful then you will see the following output.

6. Click on the Local instance you created.

7. Click on this icon to create the database schema.

8. Enter the name of your database here select the optional charset and collation values if you want and then click on apply.

9. Click on the apply button don’t change any default settings here.

10. Click on the finish button to finish the database creation.

11. You will be able to see your created database on the left panel of your screen.

12. Right-click on the database you created and click on Set, as Default Schema to use your database. Now your database is ready to use.

Conclusion

In this article, we have learned how we can create databases in MYSQL. We have explored 2 methods step by step which allow the users to create databases in MYSQL. The choice of method completely depends on the user, if the user is not comfortable with the command line environment then they can use the second method of MYSQL workbench to create the databases they want. We hope this article has helped you to learn about the CREATE Database statement in MYSQL.