Install MySQL in Ubuntu 20.04 Apache Server

MySQL server is essential to maintain a database for web application. MySQL is best suitable for relational database management system projects. Following article is going to guide you to insall MySQL in Apache server(Ubuntu 20.04 version)

MySQL Installation

First of all, login with your non root username and password with super user privileges.(If you have no idea what is it, then check the second chapter in this tutorial series. All the chapter list is present below this article).

First job is to update with latest updates. Following command would do the trick.

test@tester:~$ sudo apt update

Once all the updates are updated, we ready to download and install mysql server. Use following command for this.

test@tester:~$ sudo apt install mysql-server

It will take not more than few couple of minutes, once the software is installed, we can check the status of mysql server with the following command.

test@tester:~$ sudo service mysql status


● mysql.service – MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
Active: active (running) since Sat 2020-08-08 12:34:21 IST; 20h ago
Process: 759 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=ex>
Main PID: 811 (mysqld)
Status: “Server is operational”
Tasks: 47 (limit: 2345)
Memory: 649.5M
CGroup: /system.slice/mysql.service
└─862 /usr/sbin/mysqld

Aug 08 12:34:15 tester systemd[1]: Starting MySQL Community Server…
Aug 08 12:34:21 tester systemd[1]: Started MySQL Community Server.

If you see above kind response with active:active, it means mysql server is successfully running.

At this point, any one can access the MySQL server. We must have to restrict all unauthorized access. We achieve this by implementing MySQL security.

MySQL Security

Its time to install MySQL Security. Following command will do the magic.

test@tester:~$ sudo mysql_secure_installation

Password Component Validation

It will ask for password component validation. Following type output is going to appear on screen

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:

If you are bound to follow some kind strict password policy or for some other reason, then you must set a password other wise you can ignore it. To ignore, simply press enter key.

Root Password Creation

It will ask to set a root password for root user.

Please set the password for root here.

New password:

Re-enter new password:

Use a strong password with minimum 16 characters and use a alphanumeric password. You can use online password generator for this. It is going to ask to type the password twice. If you are copy and pasting then to paste click right mouse button. Ubuntu does not show anything while typing a password. So be careful while typing the password.

Remove Anonymous user

Then it will ask to remove anonymous user, then type y (y for yes) and then press enter.

Disable Remote Login

Then it will ask to disable remote login with yes or no option. Then type y (y for yes) and then press enter.

Remove test databases

Then it will ask to remove test databases with yes or no option. Then type y (y for yes) and then press enter.

Reload Pivilege tables

Then it will ask to reload privilege table with yes or no option. Then type y (y for yes) and then press enter.

Then finally it will show “All Done” message.

At this point, we have successfully installed mysql security.

Now lets see mysql is running or not!

Following command will let you know.

test@tester:~$ sudo mysql

If mysql is right way installed then it drive you to the MySQL command console.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.


This is the way we install mysql server and myql security in Apache Server installed in Ubuntu 20.04 operating system.