How to Install MySQL on Debian 11


 

How to Install MySQL on Debian 11. MySQL is one of the most widely used database software for several well-known applications that utilize like WordPress and many more.


In this guide you are going to learn how to install latest MySQL community server on Debian.


This setup is tested on Google cloud, so it will work on all cloud hosting services like AWS, Azure or any VPS or any dedicated servers running Debian 11.

  • Prerequisites

Root access to your server or a sudo user.

  • Step 1: Setup Initialization

Start by updating the packages to the latest version available using the following command.

sudo apt update
sudo apt upgrade
Install wget package.

sudo apt install wget
Once you have updated the setup you can start the setup.

  • Step 2: Install MySQL

To add the MySQL APT repository to your system go to the repository download page and download the latest release package using the following command.


wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
Install the release package.

sudo apt install ./mysql-apt-config_0.8.22-1_all.deb
We’re going to install MySQL version 8.0. Select OK by pressing Tab and hit Enter (as shown in the image above).

Now you can install MySQL.

sudo apt update
sudo apt install mysql-server
Once the installation is completed, the MySQL service will start automatically. To verify that the MySQL server is running, type:

sudo service mysql status
The output should show that the service is enabled and running:

 mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-02-07 09:32:48 UTC; 17s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 101929 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1148)
     Memory: 369.3M
        CPU: 805ms
     CGroup: /system.slice/mysql.service
             └─101929 /usr/sbin/mysqld

Feb 07 09:32:48 demo systemd[1]: Starting MySQL Community Server...
Feb 07 09:32:49 demo systemd[1]: Started MySQL Community Server.

  • Step 3: Secure MySQL

MySQL installation comes with a script named mysql_secure_installation that allows you to easily improve the MySQL server security.

sudo mysql_secure_installation
You will be asked to configure the VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL users passwords and improve the security.

Press y if you want to set up the validate password plugin or any other key to move to the next step.

There are three levels of password validation policy, low, medium, and strong.

Enter 2 for strong password validation.

On the next prompt, you will be asked to set a password for the MySQL root user.

If you set up the validate password plugin, the script will show you the strength of your new password. Type y to confirm the password.

Next, you’ll be asked to remove the anonymous user, restrict root user access to the local machine, remove the test database, and reload privilege tables. You should answer y to all questions.

Conclusion

Now you have learned how to install MySQL stack on Debian 11 and secure it.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Comments