Many applications require MySQL as a database.

Installing it requires just a few steps.

First update the system using

sudo apt-get update

Install server

Next, install the MySQL server using

sudo apt install -y mysql-server

Now that the database server is installed, we can create a database, a user and grant access for that user to that database.

Create database

To perform any database operations, we need to get into the prompt provided by MySQL, by entering –

sudo mysql

Once in the prompt, the database can be created using –

CREATE DATABASE <database_name>;

For example, to create a database called wordpress

mysql> CREATE DATABASE wordpress;

Create user

Now, we need to create a database user. Again, from the mysql prompt –

CREATE USER '<database_user>'@'%' IDENTIFIED with mysql_native_password BY '<password>';

The single quotes (‘) are very important.

For example –

mysql> CREATE USER 'mysqluser'@'%' IDENTIFIED with mysql_native_password BY 'mysqlpassword123';

Grant access for this user to the database

Once the user has been created it has to be granted access to the database to be able to perform all operations on it.

GRANT ALL ON <database_name>.* TO '<database_user>'@'%';

Example –

mysql> GRANT ALL ON wordpress.* TO 'mysqluser'@'%';

Now, when the application to be installed asks for the credentials of the database user we can input this information for it to access the database.