How to Install MySQL on Ubuntu 16.04

how to install mysql on ubuntu 16.04

MySQL is an all time popular relational database management system. MySQL is a part of the lamp stack installation. It is more flexible and easy to use. MySQL is a free and open source platform.

In this tutorial we are going to learn how to install and secure MySQL on Ubuntu 16.04 server.

Requirements:

To follow these steps, we need a Ubuntu 16.04 server to install MySQL.

To Install MySQL:

By default, only the latest version of MySQL is available in the apt package repository on Ubuntu 16.04. At the time of making this tutorial, Mysql 5.7 is the latest version. Let’s begin to install MySQL on Ubuntu 16.04 server.

Update the apt package on Ubuntu server to install MySQL

sudo apt-get update

After that install the MySQL package on ubuntu server

sudo apt-get install mysql-server

It will be prompted twice to create a MySQL root password during this installation process. Set a secure and strong password for root.

mysql
mysql-repeat-password

Mysql status:

After the installation process MySQL starts running. To check the status of MySQL run the command below:

systemctl status mysql
Output
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Fri 2020-05-08 02:45:09 UTC; 1 day 5h ago
  Process: 27568 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=e
  Process: 27559 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exi
 Main PID: 27567 (mysqld)
    Tasks: 32
   Memory: 173.8M
      CPU: 52.068s
   CGroup: /system.slice/mysql.service
           └─27567 /usr/sbin/mysqld

May 08 02:45:08 ip-172-31-30-207 systemd[1]: mysql.service: Service hold-off tim
May 08 02:45:08 ip-172-31-30-207 systemd[1]: Stopped MySQL Community Server.
May 08 02:45:08 ip-172-31-30-207 systemd[1]: Starting MySQL Community Server...
May 08 02:45:09 ip-172-31-30-207 systemd[1]: Started MySQL Community Server.
lines 1-16/16 (END)...skipping...
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-05-08 02:45:09 UTC; 1 day 5h ago
  Process: 27568 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 27559 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 27567 (mysqld)
    Tasks: 32
   Memory: 173.8M
      CPU: 52.068s
   CGroup: /system.slice/mysql.service
           └─27567 /usr/sbin/mysqld

May 08 02:45:08 ip-172-31-30-207 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
May 08 02:45:08 ip-172-31-30-207 systemd[1]: Stopped MySQL Community Server.
May 08 02:45:08 ip-172-31-30-207 systemd[1]: Starting MySQL Community Server...
May 08 02:45:09 ip-172-31-30-207 systemd[1]: Started MySQL Community Server.

Secure MySQL:

MySQL package includes mysql_secure_installation script for performing more security based functions.

Run the mysql security script:

mysql_secure_installation

After running MySQL security script command it will prompt to enter MySQL root password we created before during the MySQL installation. Next configure the VALIDATE PASSWORD PLUGIN to remove test databases and test passwords for more security, Press y and ENTER, then choose the password strength and ENTER, it will asks for changing of MySQL root password we created before during the MySQL installation, we don’t have change right now, press n and ENTER, after that type y and enter for all the security prompts.

Login to the Mysql:

To login MySQL server run the command below:

mysql -u root -p

Conclusion

We have successfully installed MySQL on Ubuntu 16.04 server,  now we can start creating tables and databases for storing data.

Leave a Reply

Post your comments here

You May Also Like