Create New MySQL Database

Create New MySQL Database

Every website needs unique MySQL database as well as unique MySQL database user.

1. The first thing to do before you create a new MySQL database is to login to MySQL (MariaDB) console by running the following command on PuTTY SSH client or any Linux terminal:

root@mail:~# mysql
Login to MySQL (MariaDB) Database

Create Database User

2. Then, we need to create MySQL database user (sitebase_user) for the new website by running the below command. Let’s assume that the password is: 12345678, you should use stronger password.

MariaDB [(none)]> CREATE USER 'sitebase_user'@'localhost' IDENTIFIED BY '12345678';
Create MySQL Database User

Note that we pressed: Ctrl+L, to clean the MariaDB PuTTY console before creating the database user.

Change Database User Password

You can change the password of the user by running the command:

MariaDB [(none)]> ALTER USER 'sitebase_user'@'localhost' IDENTIFIED BY 'yourNewPassword';

In order to delete the user you created, run the command:

MariaDB [(none)]> DROP USER 'sitebase_user'@'localhost';

Create Empty Database

3. After that, create an empty database (let’s give it the name: sitebase_db) by running the command:

MariaDB [(none)]> CREATE DATABASE sitebase_db;
Create MySQL Database

Delete Database

At any time, you can delete the database you created by running the command:

MariaDB [(none)]> drop database sitebase_db;

Grant Database Privileges to the User

4. Now, we need to connect the database with the user. For this purpose, we will grant privileges on sitebase_db to the sitebase_user by running the command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON sitebase_db.* TO 'sitebase_user'@'localhost' WITH GRANT OPTION;
Grant Privileges on Database to User

5. In order to make sure that our new database (sitebase_db) has been created successfully, run the below command:

MariaDB [(none)]> show databases;
Show All MySQL Databases

See All Database Users

To see the database user that we’ve created (sitebase_user), run the command:

MariaDB [(none)]> select user from mysql.user;
Show All Database Users

Note that we’ve the database username which is sitebase_user and the database name which is sitebase_db. Also, the password for the database username which is 12345678. We will use them all when we configure the WordPress in the next tutorial.