How to Install MySQL on Debian 10, 11

MySQL is a popular open-source database management system for storing and managing data. Debian, a widely used Linux distribution, offers seamless compatibility for MySQL installation across its various versions. In this guide, you will find steps required to install MySQL on Debian 10 (Buster) and Debian 11 (Bullseye) to set up a robust database system for your applications or projects.

There are a few important factors making Linux better than Windows: it is more stable, secure, and cost-effective. Of course, Linux may be somewhat more complicated in terms of setup and configuration, but all in all, it is definitely a good choice. A Linux distribution, also called a distro, is an operating system that includes the Linux kernel, a package management system, GNU tools, libraries, etc. One of the most widely used Linux distributions is Debian - an open-source Linux-based operating system created by the Debian community.

Pros of Debian

  • A strong and vast community
  • A wide range of software repositories
  • Security and stability
  • Regular updates

Debian is highly valued by software and hardware developers due to its versatility and ability to run on a wide range of architectures and devices. Its public bug tracker and extensive collection of development tools make it one of the most advantageous Linux distributions for programming. This makes Debian an ideal choice for developers. Given the crucial role that data and information play in modern applications, software programming often requires the use of database software.

What is the most popular database management system for Linux?

It is, without any doubt, MySQL. It is widely used for web applications and open-source software projects, due to its stability, robustness, and ease of use. Additionally, its compatibility with Linux operating systems, as well as its open-source nature, make it a popular choice for many organizations. Some developers even claim that MySQL works better on Linux than on Windows.

How to Install MySQL on Debian 10/11

In this article, we present a concise step-by-step guide on how to install MySQL server on Debian. We will also look into uninstallation issues and demonstrate to you how to manage MySQL on Linux using one of the best GUI tools for MySQL – dbForge Studio for MySQL.

1 - Preparing to install the latest version of MySQL Server

To start with, you need to update the local package index by running the following command. Provide a password when asked for it.

sudo apt update
Preparing to install latest version of MySQL Server

Then, to upgrade the system, run:

sudo apt upgrade

Your next steps will involve downloading and installing the MySQL .deb package with wget.

wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
Preparing to install latest version of MySQL Server

Let us check, that the download was successful. Run the following command to list all the files in the directory.

ls
Preparing to install latest version of MySQL Server

Now we need to install that package. Execute the following command for this.

sudo apt install ./mysql-apt-config_0.8.24-1_all.deb
Preparing to install latest version of MySQL Server

Next, in the Package configuration window, first, select OK and then select MySQL Server & Cluster. Click Enter to proceed.

Preparing to install latest version of MySQL Server

In the next window, select mysql-8.0 and click Enter.

Preparing to install latest version of MySQL Server

And finally, update the APT repository again.

sudo apt update

2 - Install MySQL 8

Now you are all set for installing MySQL Server 8.0. Run the following command:

sudo apt install mysql-server

Once the installation is completed, the MySQL service should start automatically. However, let us verify that the MySQL server is active:

sudo service mysql status
Preparing to install latest version of MySQL Server

3 - Secure MySQL Server

The mysql_secure_installation command helps you to improve the security of MySQL server installation. First, run:

sudo mysql_secure_installation

You will be then asked to configure the VALIDATE PASSWORD PLUGIN used to check the strength of the MySQL passwords.

Press Y/y if you want to set up the validate password plugin. Afterward, you will be asked to specify the level of password strength: low, medium, or strong. Enter 2 to select the strong password validation policy.

Next, set and confirm a password for the MySQL root user.

Then you’ll be prompted to remove the anonymous user, restrict root user access to the local machine, remove the test database, and reload privilege tables. We recommend answering Y\y to all questions.

4 - Login into MySQL

Okay, let us now try to login into MySQL server. The syntax is pretty simple here:

mysql -u root –p
Login into MySQL

To check the current status of your MySQL instance, you can run the following command:

STATUS;
Login into MySQL

How to Update MySQL on Debian

Suppose, we want to upgrade MySQL server on Debian from 5.7 to 8.0.
To begin with, let us check our current MySQL server version:

mysql –version
How to Update MySQL on Debian

Before launching the upgrade, we recommend you take the full backup of all databases that reside on the server with the following command:

mysqldump -u root -p --all-databases > /tmp/all-database.sql

Next, stop the MySQL service:

systemctl stop mysql.service

If you need to back up your MySQL data, run:

cp -r /var/lib/mysql /var/lib/mysql.backup

Now download the newer MySQL APT repository.

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

On the screens that appear, select MySQL version 8.0 and click OK.
Then update the server and install the latest MySQL using the below commands.

sudo apt-get update
sudo apt-get install mysql-server

And finally, restart MySQL service.

systemctl restart mysql.service

How to allow remote connections to MySQL server on Debian

One of the most common problems that MySQL users on Debian face is that their MySQL instance is only configured to listen for local connections. Let us look at how to allow remote connections to MySQL server residing on Debian.

To begin with, you need to add your external IP to the list of IPs that the server listens to. For this, run the following command to open the configuration file:

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

Then, navigate to the line that begins with the bind-address directive and set it to your actual IP address, or a wildcard *, or 0.0.0.0.

If you do not have the bind-address directive in your configuration file, you can add it.

How to allow remote connections to MySQL server on Debian

Now, you need to create a MySQL user with access from a specific IP address or from any host ('username'@'%').

CREATE USER 'username'@'10.10.10.10' IDENTIFIED BY 'password';

And finally, grant privileges to the newly created user.

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';

To finish with, execute the following command.

FLUSH PRIVILEGES;

How to Uninstall MySQL on Debian 10/11

The first step is to remove MySQL Server from your Debian system. For this, run the following command and enter the Debian password when asked for it.

sudo apt-get purge mysql-server mysql-apt-config

If you want to remove MySQL Server completely, including all the dependencies, run the following command:

sudo apt autoremove
Uninstall MySQL on Debian

How to manage MySQL using GUI Tool on Debian

Debian is a Linux distro that comes without a GUI installed by default. You might object that a Graphical User Interface is only a supplemental component of a Linux system, and is not essential. However, there is a bunch of tasks that are much easier to perform from a GUI like web browsing the Net, watching videos, and managing databases, of course, is one of them. dbForge Studio for MySQL is an advanced, all-in-one IDE for managing MySQL databases with intelligent coding assistance, instant formatting and syntax checker for MySQL, and powerful built-in developer tools.

You can easily connect to your MySQL server installed on Debian and work with databases in a neat and comprehensive interface. Just imagine – no need to memorize and type complicated commands – almost any MySQL-related task can be done visually. More than that, dbForge Studio for MySQL can be installed in the Linux environment via a specialized application called CrossOver, which provides a compatibility layer that allows Windows applications to run on Linux and macOS.
Let us briefly demonstrate to you how you can perform basic database tasks with the Studio.

Connect to MySQL server

To connect to MySQL server on Debian from dbForge Studio for MySQL:

  1. On the Database menu, select New Connection.
  2. On the Database Connection Properties> General tab, specify the connection details:
    • Type: Select the connection type from the drop-down list.
    • Host: Provide the host name
    • Port: Provide the port number
    • User and Password: Enter the user credential details respectively. By default, the password is saved automatically. If you don’t want to save the password, clear the Allow saving password checkbox.
    • Database: Enter the name of a MySQL database you want to connect to or select it from the drop-down list.
    • Optional: Connection Name: The connection name is generated automatically from the host name. If you want to create a distinctive name for the connection, type the new name.

Click Test Connection to verify the connection details you have provided. Click Connect to connect to a MySQL server.

Create MySQL Users

Now that you have connected to your MySQL server on Debian from dbForge Studio for MySQL, you can perform all your database-related tasks either visually, or run MySQL queries in and advanced Text Editor with extensive code-completion and syntax check capabilities.

To create a new user account in dbForge Studio for MySQL:
  1. Open the Security Manager.
  2. Click Create User above the User List or right-click a user node and select New User on the shortcut menu.
  3. Fill in the Name, Host, Password, and Confirm Password fields.
  4. Grant necessary privileges to the user.
  5. Click Save on the Security Manager toolbar.

Create MySQL Databases

To create a new database on your MySQL server that is installed on Debian, you do not need to enter commands from the command line – just connect to the server from dbForge Studio for MySQL and create a database within a few clicks.

To create a new database in dbForge Studio for MySQL:
  1. In Database Explorer, right-click a connection node and select New Database. Alternatively, select New Database on the Database menu.
  2. Enter the name of the database.
  3. Select Character set and Collation.
  4. Click Apply Changes, and, if specified name is unique, the database will appear in Database Explorer.

View and change Server Variables

dbForge Studio for MySQL allows you to quickly and easily view and modify MySQL system and status variables with the Server Variables window. To call the Server Variables window, select Server Variables on the Database menu.

To switch between system and status variables, click the System or Status buttons on the Server Variables window toolbar. To change the variable value, click the required variable in the Value column and edit it. Press ENTER to apply changes or ESC to discard them.

Back up a database

The ultimate MySQL backup tool that comes with dbForge Studio for MySQL is bound to help database administrators and developers quickly and easily back up and restore MySQL databases. With dbForge Studio you can perform the following backup tasks:

  • Back up database structure, data, or both
  • Select database objects to be included in a backup
  • Automate database backup and restore
  • Schedule database backup and restore
  • Back up and restore MySQL databases using the command line

Need a reliable solution to manage your
MySQL databases?

Get the most advanced IDE on the market - dbForge Studio for MySQL

Conclusion

Working with MySQL on Debian has its obvious advantages. The Debian operating system is freely available to everyone, there’s no need to pay for software updates or install any third-party software products. Nowadays MySQL running on Debian is a choice of many high-level developers and analysts.

Download 30 days free trial of dbForge Studio for MySQL and test-drive its impressive functionality including designing and visualizing databases, synchronizing MySQL databases, exporting and importing MySQL data, data reporting and many, many more.

Conclusion