How To Create A New Database In MySQL

Last modified on Monday 24 Jan 2022 at 04:44 pm

This article will describe step-by-step how to create a new database in MySQL in Ubuntu or Debian. This steps will basically be identical in MariaDB since it is a fork of MySQL.

How To Create A New Database In Ubuntu and Debian

Log in to MySQL
Here I will describe 2 different ways. One is logging in as root, and another way is logging in as another MySQL user.

1. Logging in as root
If you don’t already have a MySQL username, or you want to log in as root, you can type:
sudo mysql

For the above command, make sure to use your password for your account in Ubuntu (or Debian), not password that you setup for root in MySQL (assuming they are different).

2. Logging in as a MySQL username you already created
If you have already created another MySQL username, you could just login to MySQL like below. Let’s assume your username is ‘testusername’.

mysql -u testusername -p

Now, for the command to create the database in Ubuntu or Debian

The following command creates the database. Let’s assume that will will name our database ‘exampledotcomdatabase’, though, you can name the database whatever you want. We generally would 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

Your email address will not be published. Required fields are marked *