MySQL Database is a storage location where you can store the business data. Every Database uses tables to store the information in a normalizes way so that, we can easily Insert, Select, Update and Delete the business data.
In this article we will show you, How to Create Database in MySQL Server with example. Here, we will use both MySQL command prompt, and Workbench for MySQL Create Database
MySQL Create Database example
Before we start create MySQL new database, Let us see the list of available databases in MySQL Server. In order to get this information you have to use SHOW DATABASES command
Below screenshot will show you the available databases.
The basic syntax to create MySQL Database is:
CREATE DATABASE Database_Name
For the demonstration purpose, we are going to create new database called First_Database. So, Replace the Database_Name with First_Database as shown below
CREATE DATABASE First_Database;
From the below screenshot you can observe that, Command is executed successfully.
Now, let me show you the databases available. And you can see the first_database in the list
MySQL Create Database using Workbench
Before we start creating database, let me open the Workbench. From the below screenshot, you can see a list of available database under the Schemas pane.
MySQL Create Database using Query in Workbench
In this example, we create new database called second_database.
CREATE DATABASE second_database;
Click on the Execute button to execute the create database command
From the below screenshot you can can see, command is executed successfully and you can see the second_database under schemas
MySQL Create Database using Wizard in Workbench
If you are unaware or not familiar with queries then you can use workbench to create new MySQL database. To do so, within the Menu, click on the Create a New Schema in the Connected Server button.
Once you select the option, following tab window will be opened. Please change the Name of the schema from new_schema to Third_Database
You can use the Collation drop down box to change the Server Default collation.
Click the apply button to create new schema, or database.
TIP: We configured the MySQL to convert the schema names, and table names to lowercase by default. Because, we used the Third_Database as the schema, it is saying that it will convert the name to lowercase.
Click Apply button
Next, click Finish button
Now you can see the third_database under the schemas.
TIP: If you didn’t find the newly created database, Please click on the refresh button beside the Schemas
How to Check MySQL Database name exists or not
Let us see what will happen, When we create MySQL new database with existing name. From the below screenshot you can observe that, it is throwing error saying: Can’t create database third_database. database exists.
CREATE DATABASE third_database;
NOTE: In an organization, we may or may not have the privileges to know the available databases. So, it is always advisable to check whether the database name already exists or not
If you have the privilege to see the available databases then you can use the SHOW DATABASES command to see a list of databases. If not use below option.
Following statement will only execute Create Database Statement, if the third_database in not available in system database
CREATE DATABASE IF NOT EXISTS third_database;
Let me try different database name
CREATE DATABASE IF NOT EXISTS fourth_database;
Thank You for Visiting Our Blog