(Last Updated On: November 24, 2018)

This tutorial has been written to help you install MySQL 8.0 on Debian 9 / Debian 8. This guide is for a fresh installation of MySQL 8.0 on Debian 9 / Debian 8. If you have an older version of MySQL Server (e.g 5.7), you’ll need to do an in-place upgrade or dump all data, upgrade packages and re-import all database data to MySQL 8.0.

If you’re running Ubuntu 18.04 or Ubuntu 16.04 LTS system, use below guides instead:

How to Install MySQL 8.0 on Ubuntu 18.04 / 16.04

Follow steps below to Install MySQL 8.0 on Debian 9 / Debian 8.

Step 1: Add MySQL Dev apt repository

MySQL 8.0 packages are available on official MySQL Dev apt repository.

sudo apt -y  install wget
wget https://repo.mysql.com//mysql-apt-config_0.8.10-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb

Agree to configure MySQL Apt repository.

Confirm addition of MySQL 8.0 repository as default when prompted.

Then tab to <OK>  and press <Enter> key to confirm version installation.

Step 2: Install MySQL 8.0 on Debian 9 / Debian 8

Once the repository has been added, install MySQL 8.0 on Debian 9 / Debian 8 by running the following commands:

sudo apt update
sudo apt -y install mysql-server

When asked for the rootpassword, provide the password.

Re-enter root database user password.

Select the Authentication plugin and select <OK> to finish installation of MySQL 8.0 on Debian 9 / Debian 8.

Check version installed using the apt-policycommand:

$ apt policy mysql-server
mysql-server:
  Installed: 8.0.13-1debian9
  Candidate: 8.0.13-1debian9
  Version table:
 *** 8.0.13-1debian9 500
        500 http://repo.mysql.com/apt/debian stretch/mysql-8.0 amd64 Packages
        100 /var/lib/dpkg/status
     5.5.9999+default 500
        500 http://httpredir.debian.org/debian stretch/main amd64 Packages

The mysql service should be started by default, you can confirm service status using the command:

$ sudo systemctl status is-enabled mysql
Unit is-enabled.service could not be found.
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-11-24 11:26:34 UTC; 1min 54s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1917 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1952 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 37 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─1952 /usr/sbin/mysqld

Nov 24 11:26:33 deb9 systemd[1]: Starting MySQL Community Server...
Nov 24 11:26:34 deb9 systemd[1]: Started MySQL Community Server.

Step 3: Test MySQL 8.0 Installation on Debian 9 / Debian 8

Let’s test to confirm if MySQL 8.0 installed on Debian 9 / Debian 8 is working as expected.

Login as root user with created password:

$ 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.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.13    |
+-----------+
1 row in set (0.00 sec)

Create a Test database and user.

CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Jek1oleiboafei4eeghu";
CREATE DATABASE test_db;
GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';
FLUSH PRIVILEGES;
QUIT

Try to access the database console as test_user:

$ mysql -u test_user -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test_db            |
+--------------------+
2 rows in set (0.01 sec)

mysql> QUIT

Once confirmed to be able to login and use assigned database, login again as root user and drop both the test database and user.

mysql> DROP DATABASE test_db;
Query OK, 0 rows affected (0.11 sec)

mysql> DROP USER 'test_user'@'localhost';
Query OK, 0 rows affected (0.11 sec)

mysql> SELECT USER FROM mysql.user;
+------------------+
| USER             |
+------------------+
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+
4 rows in set (0.00 sec)

mysql> QUIT
Bye

MySQL 8.0 has been confirmed to be installed and working on Debian 9 / Debian 8. Thank you for using our guide and stay connected for more articles related to Database Administration.