How To Create A New Database In MySQL

This article will describe step-by-step how to create a new database in MySQL in Ubuntu (16.04 and 14.04) and the steps will be similar in Debian. This steps will basically be identical in MariaDB since it is a fork of MySQL.

How To Create A New Database In Ubuntu 16.04

Since the introduction of Ubuntu 16.04, the steps for how to initially logging into MySQL have changed a little. You will no longer be able to login by default, at least initially by typing mysql -u root -p. You will need to do
sudo mysql. While I definitely preferred logging into to MySQL with Ubuntu 14.04, it’s not really much harder in Ubuntu 16.04

Then use the following steps to create a new username in Ubuntu 16.04
Login To MySQL
sudo mysql
For the above command, make sure to use your password for your account in Ubuntu, not password that you setup for root in MySQL (assuming they are different). Or, if you have already created another MySQL username, you could just login to MySQL like this. Let’s assume your username is ‘testusername’.

mysql -u testusername -p

Now, for the command to create the database in Ubuntu 16.04

The following command creates the database. Let’s assume that our database is ‘exampledotcomdatabase’. Though, you can call the database whatever you want. We want to use UTF-8 encoding when creating the database.
CREATE DATABASE exampledotcomdatabase CHARACTER SET utf8;

Next, after entering the above line, you should see output like:

Query OK, 1 row affected (0.00 sec)

#Now exit MySQL

exit

We exited mysql after creating the database just to make sure we did everything correctly.

#Log back into mysql either as root or as a username you created
either type
sudo mysql
or type
mysql -u testusername -p

#Next, make sure that our database was created properly
In mysql type:
show databases;

You should see output like:
+———————–+
| Database |
+———————–+
| exampledotcomdatabase |
| information_schema |
| mysql |
| performance_schema |
+———————–+

You should now have a new database in MySQL called exampledotcomdatabase.

How To Create A New Database In Ubuntu 14.04

First login to MySQL. I’m going to assume you are logging in as the root user.

mysql -u root -p

Make sure to use the password for root that you setup with your mySQL installation.

Now, for the command to create the database in Ubuntu 14.04

The following command creates the database. Let’s assume that our database is ‘exampledotcomdatabase’. Though, you can call the database whatever you want. We want to use UTF-8 encoding when creating the database.
CREATE DATABASE exampledotcomdatabase CHARACTER SET utf8;

Next, after entering the above line, you should see output like:

Query OK, 1 row affected (0.00 sec)

#Now exit MySQL

exit

We exited mysql after creating the database just to make sure we did everything correctly.

#Log back into mysql either as root or as a username you created
either type
sudo mysql
or type
mysql -u testusername -p

#Next, make sure that our database was created properly
In mysql type:
show databases;

You should see output like:
+———————–+
| Database |
+———————–+
| exampledotcomdatabase |
| information_schema |
| mysql |
| performance_schema |
+———————–+

You should now have a new database in MySQL called exampledotcomdatabase.

Did you like this article? Do you have anything to add? Let’s discuss it in the comments below.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.