How to Install MySQL Server on Debian 10/11 (Installation Tutorial)

MySQL is a relational database management system that is widely used around the world. It’s GPL-licensed open-source software . It’s a widely used database management system for storing and retrieving data for a variety of uses and it is open source. This article will provide a step-by-step tutorial on how to install MySQL Server 8.0 on Debian 10/11.

MySQL server on Linux is a high speed, sturdy, and appropriate multi-user SQL database server which is also multi-threaded, with speed, durability, and convenience of use as its primary goals. The LAMP stack is an extensively used collection of open source software that includes Linux, Apache Web Server, and PHP Programming Language, it is widely used. MySQL comprises the M in the LAMP stack.

Debian 10 and 11 come with MySQL in its repository, however as many know, Debian stable provides only security updates for its releases in line with keeping its stable build essentially stable. This has great benefits but some drawbacks; in the tutorial, you will learn how to install MySQL 8 for Debian 10/11.

MariaDB on Linux is a MySQL fork created for the MySQL community server, it is the default MySQL variant in Debian 10 and 11. MariaDB mostly functions well, if you require features only available in Oracle’s MySQL, you install packages from the MySQL developers’ repository.

In this tutorial this repository will be configured, the MySQL software mentioned above will be installed, the installation will be secured, and finally we will test that MySQL is running and responding to commands.

Install MySQL on Debian 10/11

Table of Contents

MySQL Server Prerequisites

Before following the tutorial for installation of MySQL server, you will need to set up:

 

  • A Debian 10 server is set up, including a non-root user with Sudo privileges and a firewall.
  • You will need SSH access to your Debian Server.

Download MySQL Software Repository

To add the MySQL APT repository, download the latest release package using the wget command below  to your system from this download page:

				
					wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb
				
			

Once the download is completed install the release package a with the following command as a user with Sudo privileges:

				
					sudo apt install ./mysql-apt-config_0.8.13-1_all.deb
				
			

You will be presented with the configuration menu from where you can select the MySQL version you want to install.

As shown in the image above, we’re going to install MySQL version 8.0 already selected. Press OK by and hit Enter.

Install MySQL Server

We will now 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 your root password for MySQL. leave it blank for now as we will set our password in the next section.

Next, the new MySQL 8 authentication message will be displayed in front of you. (Before selecting the default plugin for MySQL 8 authentication ensure your application supports it).

We’re installing  MySQL version 8.0. As shown in the image above, version 8.0 is pre-selected. Press OK then hit Enter.

Check MySQL Server Service Status

After completion of installation, the MySQL service will start automatically, and can be verified by running the following command:

				
					sudo systemctl status mysql
				
			

Your output should look like this:

				
					mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Fri 2021-11-08 13:23:25 PDT; 37s ago
   ...

				
			

Now to set the root password to further the security of your installation run the following command:

				
					sudo mysql_secure_installation
				
			

You will be presented with the following output:

				
					Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:

				
			

Now you will 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.

Next, you will be asked to set a password for the MySQL root user.

Your Output will then look like this:

				
					Please set the password for root here.

New password:

Re-enter new password:

				
			

Now the following prompt will appear:

				
					By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

				
			

Once you set the root password you will be asked 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 in the prompt above.

Access MySQL Database Terminal

To interact with MySQL through the terminal, use the MySQL client which is installed as a dependency of the MySQL server package.

If the method you selected to log into the MySQL server, is the default one as described above, as the root user, enter:

				
					sudo mysql
				
			

On the other hand if you selected the authentication via legacy method, enter:

				
					mysql -u root -p
				
			

Next, the prompt to enter the root password you previously set when the mysql_secure_installation script was run will be presented. Once you enter the password the MySQL shell should display the following output:

				
					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
...

				
			

Installation of MySQL Server on Debian 10/11- Final Thoughts

You learned how to install the latest MySQL server version 8.0 and secure it as well on a Debian 10/11 server via this guide. We’ve also demonstrated how you can access the shell configured with MySQL.

Overall, MySQL 8.0 performs better for reading/writing workloads, IO-bound workloads, and workloads with high contention. There are options to significantly improve  specific workloads on specific hardware by charting threads of users to the CPU, to name a few of the innovative capabilities. Users who are still using older versions of MySQL should think about upgrading because the performance gains are well worth it.

Thanks for following this tutorial for installing the latest version of MySQL 8 on Debian 10/11. We suggest that you check the official MySQL website if you require additional assistance or information.

Hopefully, you have been able to successfully follow all the steps above and have installed the MySQL server on your device. Happy Coding!

Avatar for Emad Bin Abid
Emad Bin Abid

I'm a software engineer who has a bright vision and a strong interest in designing and engineering software solutions. I readily understand that in today's agile world the development process has to be rapid, reusable, and scalable; hence it is extremely important to develop solutions that are well-designed and embody a well-thought-of architecture as the baseline. Apart from designing and developing business solutions, I'm a content writer who loves to document technical learnings and experiences so that peers in the same industry can also benefit from them.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x