MySQL is the word`s most popular open source relational database management system. It is not available in the default Debian’s repositories.
In this article,we will show you how to install and secure MySQL on Debian 9/10 from the the MySQL Apt Repository.
01、Configuring MySQL Repository
Open your browser visit the MySQL download page and download the latest release package using the following wget command:
Install the release package as a user with sudo privileges
sudo apt install ./mysql-apt-config_0.8.13-1_all.deb
You will see the the configuration menu from where you can select the MySQL version you want to install.
MySQL 8.0 is pre-selected, if you want to install MySQL 5.7, select
MySQL Server & Cluster (Currently selected: mysql-8.0) and choose your preferred MySQL version.
In this aritcle,We’re going to install MySQL version 8.0. Select
OK by pressing
Tab and hit
Enter (as shown in the image above).
02、Install MySQL on Debian 9/10
Update the package list and install the MySQL server package by running:
sudo apt update sudo apt install mysql-server
The installer will ask you to set the MySQL root password.Do not set it now(leave it blank),we will do that in the next section.
Once the installing is completed,the MySQL server willl start automatically,you can verify it by type the following command:
sudo systemctl status mysql
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en Active: active (running) since Fri 2019-11-21 13:23:25 PDT; 37s ago ...
You can run the
mysql_secure_installation command to set the root password and improve the security of the MySQL installing:
You will be asked to configure the
VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL users passwords. There are three levels of password validation policy, low, medium and strong. Press
ENTER if you don’t want to set up the validate password plugin.
Please set the password for root here. New password: Re-enter new password:
On the next prompt, you will be asked to set a password for the MySQL root user.
Once you set the root password the script will also ask you to remove the anonymous user, restrict root user access to the local machine and remove the test database. You should answer “Y” (yes) to all questions.
04、Connecting to the MySQL Server
To interact with MySQL through the terminal, use the
mysql client which is installed as a dependency of the MySQL server package.
you can selected the default authentication method to log in to the MySQL server as the root user type:
you can alse selected the legacy authentication method to log in type:
mysql -u root -p
You will be prompted to enter the root password you have previously set when the
mysql_secure_installation script was run. Once you enter the password you will be presented with the MySQL shell as shown below:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.17 MySQL Community Server - GPL ...
In this tutorial, you’ve learned how to install and secure a MySQL server on a Debian 8/9/10 server. We have also shown you how to connect to the MySQL shell.
If your application does not have any specific requirements, you should stick with MariaDB, the default database system in Debian 8/9/10.