Databases allow you to store,retrieve and process data for business and other purposes. In this article, we will look at how to create database in MySQL.
How To Create Database in MySQL
Here are the steps to create new database in MySQL using MySQL CREATE DATABASE command.
Here’s its syntax
CREATE DATABASE [IF NOT EXISTS] database_name [CHARACTER SET charset_name] [COLLATE collation_name]
In the above query, database_name is the name of your new database. Please note, it must be unique to your MySQL server instance. Otherwise, you will get an error.
IF NOT EXISTS is an optional argument that checks if the database already exists and creates database only if it doesn’t exist.
CHARACTER SET option allows you to specify the character set to be used in MySQL database. By default, it is latin1. Similarly, the default COLLATION of MySQL database is latin_swedish_ci. If you want your database to support unicode characters then you will need to change its CHARACTER SET and COLLATION.
Bonus Read : How to Create Table in MySQL
MySQL CREATE DATABASE Examples
Here’s an example of how to create MySQL database.
mysql> create database testdb; mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | dashboard | | fedingo | | mysql | | performance_schema | | sample | | test | | testdb | +--------------------+ mysql> use testdb;
Bonus Read : How to Add Foreign Key in MySQL
You can use USE database_name command to change your current active database. Hopefully, now you can create database in MySQL. You can use the above article to create database in PostgreSQL, SQL Server and Oracle also.