## Table of Contents
– [Install the Latest MySQL on Debian 9](#install-the-latest-mysql-on-debian-9
– [Add the MySQL APT Repository](#add-the-mysql-apt-repository
– [Install MySQL](#install-mysql
– [Secure MySQL](#secure-mysql
– [Test MySQL](#test-mysql
In this guide, we are going to explain to you how to install the Latest MySQL on Debian 9 and some additional recommended steps that you must take to increase the usability and security of your server.
[MySQL](https://www.mysql.com/ is one of the most popular open-source database management systems in the world. It uses a relational database and a [Structured Query Language (SQL](https://en.wikipedia.org/wiki/SQL to manage data. Debian 9 prefers [MariaDB](https://mariadb.org/, which is developed by the MySQL developers as a replacement for MySQL. MariaDB is the default MySQL variant on Debian 9. So, if you want MariaDB installation for reference, follow our guide, [How to Install MariaDB on Debian 9](https://systemongrid.com/support/guides/-how-to-install-mariadb-on-debian-9. Between MySQL and MariaDB, [MariaDB is the preferable package and can work better](https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/.
Before installing MySQL on Debian 9, you should have access to the Debian 9 server, created a non-root user account with sudo privileges and set up a firewall by following our guide, [Initial server setup with Debian 9](https://systemongrid.com/support/guides/initial-server-setup-with-debian-9.
## Install the Latest MySQL on Debian 9
## Add the MySQL APT Repository
As we mentioned earlier, Debian 9 prefers MariaDB. So, you need to visit the MySQL APT Repository which provides MySQL packages.
Locate the desired MySQL version and update it using the below command.
$ cd /tmp
$ wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
After saving the rpm file, verify the authenticity of the download using the below the command.
$ md5sum mysql-apt-config_0.8.12-1_all.deb
Verify your output with the relevant MD5 value on MySQL APT Repository website.
If it is matched, you are all set to install.
$ sudo dpkg -i mysql-apt-config*
Then, you will get the following screen. Select your preferred version of MySQL. Then, go to “ok” menu option and hit the ENTER button.
Then, refresh the cache of your apt package to make the new packages available.
$ sudo apt update
## Install MySQL
Use the apt command to install the latest MySQL server package.
$ sudo apt install mysql-server
Then, you will be asked if you want to continue the installation, then enter “Y”, hit the ENTER button.
Then, you will get the following screen and asked to enter the root password. enter a strong password, confirm it by re-entering and hit on “ok”.
Then, you will see the below screen. Read it and hit on “ok”.
Then, you are asked to select a default authentication plugin. Select the option, Use Strong Password Encryption and hit on “ok”.
With this, you have successfully installed the MySQL and it is running now. Check the status of the MySQL using the below command.
$ sudo systemctl status mysql
The above output shows that your MySQL is installed and running successfully.
## Secure MySQL
MySQL uses a security script to modify the default security options like remote logins. Use the below command to run the security script.
$ sudo mysql_secure_installation
The script will ask you to give a password for further use within the MySQL system. Then, you will be asked, if you want to configure the VALIDATE PASSWORD PLUGIN. Press Y for yes, or any other key to continue without enabling.
Then, you will be asked to select a level of password validation.
Select any one among three levels of password validation, enter your new password. Then, you will be shown the strength of the password you have entered. Press Y if you are satisfied with the password.
Then, you will be asked if you want to remove anonymous users. Press Y for yes, or any other key to continue. (We recommend accepting all the below security suggestions by entering “Y” in each step.
Then, you will be asked if you want to disallow root login remotely. Press Y for yes, or any other key to continue.
Then, you will be asked to remove the test database. Press Y for yes, or any other key to continue.
Then, you will be asked to reload privilege tables. Press Y for yes, or any other key to continue.
## Test MySQL
You can test your installation and know the information about it. For that, you need to connect to MySQL as root user (or, a user with password authentication using the below command.
$ mysqladmin -u root -p version
The above output shows that you have successfully installed the latest MySQL on Debian 9.
In this guide, you have learned how to install the latest MySQL on Debian 9 and some additional recommended steps that must be taken to increase the usability and security of your server.