We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Install MySQL 5.7 on Debian 11/Debian 10

Learn how to – How To Install MySQL 5.7 on Debian 11/Debian 10.

In this article, we are going to look at how to Install MySQL 5.7 on Debian 11 and Debian 10. MySQL is one of the most widely used relational databases. We are going to install the community edition which is a free to installed software managed under General Public License.

Step 1: Add MySQL Repository on Debian 11 / Debian 10

Let’s download and install mysql repository set up package on Debian 11 and Debian 10. Run the below command

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

Once downloaded, we need to install the repository package.

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

Note that MySQL 5.7 repository is not yet availaible for Debian 11 (Bullseye). In this case, we are going to select Debian 10 (Buster) for both Debian 11 and Debian 10.

Ensure mysql-8.0 is selected.

Next select mysql-5.7 as shown

Next, use the down arrow key to select Ok then click Ok and the package will be installed.

Step 2: Install MySQL 5.7 Server on Debian 11 / Debian 10

Since we have installed the repository for MySQL 5.7, we will now proceed to install MySQL 5.7 on Debian 11 and Debian 10. First update repository index

sudo apt update

Import missing GPG keys on Debian 11

If you encounter signatures couldn’t be verified errors similar to below:

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 467B942D3A79BD29

Then import missing GPG key(s) with below command:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.lBFUIjtfz9/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
gpg: key 467B942D3A79BD29: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Rerun apt update command to check if it works:

sudo apt update

Install MySQL 5.7 server package on Debian 11 / Debian 10

Then install mysql server as below

sudo apt install -y mysql-community-server

Set your preferred root password when prompted

Installation success output sample:

...
Unpacking libnuma1:amd64 (2.0.12-1+b1) ...
Selecting previously unselected package mysql-community-client.
Preparing to unpack .../mysql-community-client_5.7.37-1debian10_amd64.deb ...
Unpacking mysql-community-client (5.7.37-1debian10) ...
Selecting previously unselected package mysql-client.
Preparing to unpack .../mysql-client_5.7.37-1debian10_amd64.deb ...
Unpacking mysql-client (5.7.37-1debian10) ...
Selecting previously unselected package libmecab2:amd64.
Preparing to unpack .../libmecab2_0.996-14+b4_amd64.deb ...
Unpacking libmecab2:amd64 (0.996-14+b4) ...
Selecting previously unselected package mysql-community-server.
Preparing to unpack .../mysql-community-server_5.7.37-1debian10_amd64.deb ...
Unpacking mysql-community-server (5.7.37-1debian10) ...
Setting up libmecab2:amd64 (0.996-14+b4) ...
Setting up libnuma1:amd64 (2.0.12-1+b1) ...
Setting up mysql-community-client (5.7.37-1debian10) ...
Setting up mysql-client (5.7.37-1debian10) ...
Setting up mysql-community-server (5.7.37-1debian10) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.

Step 3: Start MySQL Service

When installed MySQL service is not started by default. Start it and also enable it to be automatically starting whenever the server is rebooted.

sudo systemctl restart mysql
sudo systemctl enable mysql

Confirm status as below:

$ systemctl status mysql
 mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: active (running) since Thu 2022-01-06 13:04:38 EAT; 10s ago
   Main PID: 3666 (mysqld)
      Tasks: 27 (limit: 2322)
     Memory: 174.6M
        CPU: 250ms
     CGroup: /system.slice/mysql.service

Step 4: Secure MySQL 5.7 on Debian 11 / Debian 10

Secure your MySQL DB installation. Since we had already set the root password, you will be prompted to enter it to continue and you will also be asked if you would like to change. Respond accordingly as you wish.

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

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

Step 5: Connect To MySQL Server using mysql client

At this point, we have successfully installed MySQL 5.7 on Debian. We can connect to it as below using 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 6
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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>

Let’s create a test database

mysql> CREATE DATABASE testdb;
Query OK, 1 row affected (0.00 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.01 sec)

mysql>

You can confirm MySQL installed version as shown below:

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 5.7.36                       |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| tls_version             | TLSv1,TLSv1.1,TLSv1.2        |
| version                 | 5.7.36                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86_64                       |
| version_compile_os      | Linux                        |
+-------------------------+------------------------------+
8 rows in set (0.01 sec)

Step 6: Allow MySQL Remote Connections

If you want to be accessing MySQL database remotely, you can allow with the below commands

# open MySQL port 3306 on the firewall
sudo ufw allow mysql

# allow specific addresses to connect to mysql
sudo ufw allow from 192.168.100.222 to any port 3306

That’s it for the installation of MySQL 5.7 on Debian 11 and Debian 10. I hope the guide has been helpful. Check other articles you might be interested in below:

Cart

Your Cart is Empty

Back To Shop