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:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.26-1_all.deb
Install the .deb:
sudo dpkg -i mysql-apt-config_x.x.x-x_all.deb
where x.x.x-x is the MySQL version.
For example:
sudo dpkg -i mysql-apt-config_0.8.26-1_all.deb
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:
Select the version you will use. Once selected, it will bring you to the previous menu — press Ok button:
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
When apt finishes downloading, the installer will ask for a root password:
You have two options:
- Leave the password blank: the server will use unix sockets authentication. It means you can only access the server as a root user or as a user with sudo;
- Set a password: the authentication method will be the same for other users.
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:
Now, check the service status with systemctl:
systemctl status mysql.service
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):
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:
ufw allow $yoursqlport
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.