07.06.2023

How to Install MySQL on Debian 10

In this article, you will learn how to install the MySQL Server on Debian 10.x. It also works on another Linux-based distribution (like Ubuntu).

In the Serverspace you can create a server with already installed app "MySQL".

How to install MySQL on Debian 10:

Step 1. Add the MySQL Repository

At first, let's update the packages:

apt update
apt install gnupg

Next, download MySQL from the offical page or use wget command:

wget https://dev.mysql.com/get/mysql-apt-config_x.x.x-x_all.deb

where x.x.x-x is the MySQL version (for example, 0.8.15-1):

Screenshot 1. Download MySQL.

Install the .deb:

sudo dpkg -i mysql-apt-config_x.x.x-x_all.deb

where x.x.x-x is the MySQL version.

When you attempt to install the package, it will ask you what product and version you want to install. Here you can select The MySQL version, Tools, Connectors (like MySQL Workbench), and preview packages. To select the version, hit the first option:

Screenshot 2. Choose MySQL Server & Cluster.

Select the version you will use. Once selected, it will bring you to the previous menu — press Ok button:

Screenshot 3. Select the version you will use.

Update the apt repository:

apt-get update

The package for installing the server is «mysql-community-server» and its version is the same you have selected before in the package installer.

Step 2. Install the MySQL Server

Install the MySQL Server using the command:

sudo apt-get install mysql-community-server

Screenshot 4. Installation process.

When apt finishes downloading, the installer will ask for a root password:

Screenshot 5. Enter the root password.

You have two options:

If you set a password, the installer will ask which authentication plugin to use, strongly encrypted password (MySQL 8.x), or legacy method (MySQL 7.x and earlier). To select options use arrows or the Tab button. You must select a method that is compatible with your client/program. WOnce you have selected all options, the installation process will be finished and the service will start automatically:

Screenshot 6. Select the default authentication plugin.

Now, check the service status with systemctl:

systemctl status mysql.service

Screenshot 7. Checking service status.

If you see "active", it means that the server is running without errors. Press Q or Ctrl + C to exit.

Next, run the command as a root user to safely configure the SQL service:

mysql_secure_installation

The program will ask you questions. You will need to answer Yes (Y/y button) or No (any other key):

Screenshot 8. Running mysql_secure_installation.

If you want to allow remote access, edit the file «mysqld.conf» in etc/:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

At the end of the file, add the option "bind_address" with the value of localhost:

bind-address=127.0.0.1

Save the file and restart the service with systemctl:

systemctl restart mysql

Note: remember to open the MySQL port (it will be good to specify the standard MySQL port). If you use ufw:

where instead of yoursqlport write your MySQL port.

If you use iptables:

iptables –A INPUT –p tcp –dport $yoursqlport –j ACCEPT

where instead of yoursqlport write your MySQL port.