How to install MySQL on Ubuntu 16.04

install mysql on ubuntu 16.04MySQL is the world’s most popular open-source relational database management system (RDBMS). It is widely used for building web applications and is an important part of the LAMP open-source web application software stack. In this tutorial we are going to show you how to install MySQL on a Linux VPS running Ubuntu 16.04 as an operating system.

The first thing you need to do is to connect to your server via SSH and update all your system software to the latest version available. Go ahead and run the following command:

sudo apt-get update && sudo apt-get -y upgrade

Once your system is updated, you can proceed with the other steps of this tutorial.

The installation of MySQL database server on an Ubuntu VPS is very easy. All you need to do is to run the command below:

sudo apt-get install mysql-server

The apt package manager will install MySQL database server as well as all its dependencies on your server. During the installation you will be prompted to set a password for the MySQL root user so make sure that you choose a strong one.

The first thing you need to do after the installation of MySQL is to harden the database server. MySQL includes a script which will help you to achieve that. Go ahead and run the security script:

sudo mysql_secure_installation

Follow the on-screen messages as follows:

Securing the MySQL server deployment.

Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

New password:

Re-enter new password:

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

Once you are done with the MySQL secure installation, you can start the MySQL server and enable the service on system boot:

sudo systemctl restart mysql
sudo systemctl enable mysql

One of the most important things when running MySQL on a production server is to get the most out of its performances. If you are a beginner and you do not know how to tune your MySQL server, you can start with a program called MySQLTuner. It will help you to analyze your server and to tune MySQL for better overall performances. We have written a tutorial about how to install and use MySQLTuner on Ubuntu.

Another useful guide that you might like to check is the guide about basic MySQL database administration on a Linux VPS.

Of course you don’t have to do any of this if you use one of our Linux VPS hosting services, in which case you can simply ask our expert Linux admins to install MySQL for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

How to Install ATutor on Ubuntu 14.04
Show All Users in MySQL
Install Nextcloud on Ubuntu 16.04

Free Migration to RoseHosting. Award Winning Linux VPS Hosting with Fully Managed Support. Coupon RHBLOG50 for 50% offOrder Now