Install MySQL on Debian 10/11

MySQL isn’t available in the official repository of Debian 10/11, MariaDB (fork of MySQL) is the default packages. When you decide to use MySQL instead of MariaDB, the first time you have to do is installing the MySQL APT repository.

Let’s download and install MySQL APT Repository from https://dev.mysql.com/downloads/repo/apt/, run the command bellow

wget https://dev.mysql.com/get/mysql-apt-config_0.8.25-1_all.deb

Once downloaded, install the repository package:

sudo dpkg -i mysql-apt-config_0.8.25-1_all.deb

In MySQL Package Configuration, feel free to choose MySQL Server version. You may disable MySQL Tools & Connector and MySQL Preview Packages if you only install MySQL server packages.

When finished, refresh your apt package cache to make MySQL packages available:

sudo apt update

Now you can use apt to install MySQL server package:

sudo apt install mysql-community-server

You will be asked to set a root password during the configuration phase of the installation.

After MySQL server installed, to check it’s running by using systemctl

sudo systemctl status mysql

After MySQL installed and running, run mysql_secure_installation to perform a few security-related updates on your new install.

mysql_secure_installation

You will be asked a series of security-related prompts:

  • Setup VALIDATED PASSWORD plugin to check the strength of password and to allow the users to set only those passwords which are secure enough. If you choose Y, you’ll be prompted again the level of password validation policy.
  • Change the root password? Press Y if you want to change.
  • Remove anonymous users? Press Y if you want to remove them.
  • Disallow root login remotely? If you want to access root login remotely, you should press N, otherwise root is only allowed to connect from localhost.
  • Remove test database and access to it? Press Y to remove it in your production server.
  • Reload privilege tables now? Press Y.

Finally, connect to MySQL Server using MySQL Client with the root password set earlier:

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>