How to install Mysql Server 8 on Debian 11

MySQL is an open-source relational database management system. Its one of the popular relational management system.

Mysql is commonly installed as part of the popular LAMP or LEMP (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It implements the relational model and Structured Query Language (SQL) to manage and query data.

In this guide we are going to install mysql 8 on Debian 11.

Table of Content

  1. Ensuring the server is Up to date
  2. Set up the repo for mysql 8 installation
  3. Installing Mysql 8 server
  4. Starting and enabling mysql service
  5. Testing mysql installation

Ensuring the Server is Up to date

Before proceeding, let us ensure that our debian server is up to date. Use this command to update the server packages:

1
2
sudo apt update
sudo apt upgrade -y

Next, let us install common packages that we will need in our tutorial

1
sudo apt install -y curl vim

Set up the repo for mysql 8 installation

Mysql server 8 is not available in the default Debian repositories. The mysql team provides a downloadable .deb file that will configure the repositories for mysql server 8 installation. Download it with this command:

1
curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.26-1_all.deb

You should see an output almost similar to this:

1
2
3
4
5
$ curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.26-1_all.deb
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 35548  100 35548    0     0   104k      0 --:--:-- --:--:-- --:--:--  104k

Once the download is done, we need to install the downloaded deb file. Use this command to install:

1
sudo dpkg -i ./mysql-apt-config_0.8.26-1_all.deb

This will open a configuration window prompting you to choose mysql server version and other components such as cluster, shared client libraries, or the MySQL workbench.

For now since we are only interested in the Mysql Server Installation, leave the default (Mysql Server and cluster) settings and click OK to proceed.

This is the output on successful installation and configuration.

1
2
3
4
5
6
7
$ sudo dpkg -i ./mysql-apt-config_0.8.26-1_all.deb

Selecting previously unselected package mysql-apt-config.
(Reading database ... 61010 files and directories currently installed.)
Preparing to unpack .../mysql-apt-config_0.8.26-1_all.deb ...
Unpacking mysql-apt-config (0.8.26-1) ...
Setting up mysql-apt-config (0.8.26-1) ...

Installing Mysql 8 server

Now that the repos have been added to include mysql server, we can now install the mysql-server package. First, refresh the repositories to get the latest from the added repo:

1
sudo apt update

Then Install Mysql 8 Server using this command:

1
sudo apt install -y mysql-server

Enter your administrator credentials, and the system will install the MySQL server package, client packages, and database common files.

The installation will prompt you to enter and confirm a root user and password for the MySQL database.

Use this command to check the info of the installed package to confirm that we installed the mysql version that we want:

1
2
3
4
5
6
7
8
$ apt-cache policy mysql-server
mysql-server:
  Installed: 8.0.27-1debian11
  Candidate: 8.0.27-1debian11
  Version table:
 *** 8.0.27-1debian11 500
        500 http://repo.mysql.com/apt/debian bullseye/mysql-8.0 amd64 Packages
        100 /var/lib/dpkg/status

Starting and enabling mysql service

In debian, Mysql server will be styarted by default. Check the status of the service to confirm that it is actually running:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
$ sudo systemctl status mysql

● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-11-24 04:47:23 UTC; 2min 31s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 15747 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/>
   Main PID: 15782 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 4626)
     Memory: 356.7M
        CPU: 911ms
     CGroup: /system.slice/mysql.service
             └─15782 /usr/sbin/mysqld

Nov 24 04:47:22 debiansrv.citizix.com systemd [1]: Starting MySQL Community Server...
Nov 24 04:47:23 debiansrv.citizix.com systemd [1]: Started MySQL Community Server.

The Active: active (running) since ... indicates that the service is up and running.

To enable the service to start on reboots, use this command:

1
sudo systemctl enable mysql

To view the MySQL 8 service log as follows using the journalctl command:

1
2
sudo journalctl -u mysql -xe
sudo tail -f /var/log/mysql/mysqld.log

5. Testing MySQL Installation

Let us check mysql version with this command:

1
2
3
$ mysql -V

mysql  Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)

Now you can Login as the root user and the password specified above.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 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> select version();
+-----------+
| version() |
+-----------+
| 8.0.27    |
+-----------+
1 row in set (0.00 sec)

mysql>

Conclusion

In this article, we managed to install and test mysql 8 installation on Debian 11.

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy