There’s a good possibility that if you host a website on a Linux VPS Server, you’ve used WordPress as your website’s content management system before. You must install the LAMP stack on your VPS in order to set up a MySQL database for WordPress. We’ll show you how to set up your MySQL database on WordPress in this tutorial.
Step 1: Log In With Root Account
Firstly, we will need to log into your MySQL root account by entering the following command in your terminal.
sudo mysql -u root -p
Enter the root password that you had set for during your MySQL installation when prompted.
Step 2: Create Database
After that, you will want to create a new database for your WordPress, and to do that, open your MySQL terminal and run the following command.
CREATE DATABASE <database_name> DEFAULT CHARACTER SET utf COLLATE utf8_unicode_ci;
Replace “<database_name>” with a database name of your preference in the command above.
Step 3: Create User Account
After that, we will need a new MySQL user account to operate the newly made database. To create the new user account, enter the following code into the MySQL terminal and run it
GRANT ALL ON <database_name>.* TO '<username>'@'localhost' IDENTIFIED BY '<password>';
Replace “<username>” with a username of your preference. To set your password, replace the “<password>” with a complex and strong password of your own.
Step 4: Save changes
Finally, to save changes, flush the privileges in the MySQL terminal as the following code to implement all the changes made.
FLUSH PRIVILEGES;
After you have saved changes, exit MySQL with the following command and you have finished setting up your database on WordPress with MySQL.
EXIT;