Install MySQL 8 on Debian 9

Last Updated:

This guide will demonstrate how to install MySQL 8 on Debian 9.

Install MySQL 8 on Debian 9

To install MySQL 8 on Debian 9, we are going to use MySQL APT repository which provides deb packages for installing and managing the MySQL server, client, and other components.

Run System Update

Update your system packages.

apt update
apt upgrade

Add MySQL APT Repository

MySQL APT repository is not available on the default Debian 9  system software repository list. Therefore, download the repo and install it as shown below;

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

During the installation, you will be prompted to select MySQL product version to install. Leave the defaults and select Ok and press Enter to install the repo.

install MySQL 8 on Debian 9

Once the installation is done, you need to run system update to load package list.

apt update

Install MySQL 8 on Debian 9

Now that you got MySQL APT repos in place, you can now install MySQL 8 by running the installation commands below;

apt install mysql-server

During the installation, you will be prompted to set MySQL root password. Hence, set the password and re-enter it when prompted.

Install MySQL 8 on Debian 9

Next, set the authentication plugin. Select the recommended option and proceed.

MySQL 8 authentication method

Want to install MySQL 8 on FreeBSD 12? See the link below;

Install MySQL 8 on FreeBSD 12

Running MySQL 8

MySQL 8 should be running immediately after the installation. Check status by executing the command below;

systemctl status mysql.service 
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-06-21 07:58:25 EDT; 2min 30s ago
     Docs: man:mysqld(8)
  Process: 2822 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 2857 (mysqld)
    Tasks: 37 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─2857 /usr/sbin/mysqld

Jun 21 07:58:24 debian9 systemd[1]: Starting MySQL Community Server...
Jun 21 07:58:25 debian9 systemd[1]: Started MySQL Community Server.

It is also set to run on system boot by default.

systemctl is-enabled  mysql.service 

MySQL 8 initial Security

MySQL comes bundled with a security script called mysql_secure_installation that is used to improve MySQL installation security. The script can run with no options as shown below.

Securing the MySQL server deployment.


Next, you are prompted whether to enable the validate password plugin that is used to enforce password complexity. Type Y and press Enter to enable or any other key to ignore.

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: Y

If you accept to enable the validate password plugin, you will be prompted to choose the level of complexity, with three levels provided. Choose the level and press ENTER to proceed.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

Next, you are prompted whether to reset or use existing root password.

Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : ENTER to retain existing password

Once the next prompts, press Y and enter to remove anonymous users, disallow remote root login, remove test databases and reload privileges tables to apply the changes.

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

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 

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

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

 - Removing privileges on test database...

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

All done!

MySQL 8 is now installed and running on Debian 9. You can check the version of MySQL as a way of verifying the installation. You can simply use mysqladmin to check the version instead of logging in running the select version query.

mysqladmin -u root -p version
Enter password: 
mysqladmin  Ver 8.0.16 for Linux on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2000, 2019, 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

Server version		8.0.16
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			21 min 42 sec

Threads: 2  Questions: 13  Slow queries: 0  Opens: 144  Flush tables: 3  Open tables: 48  Queries per second avg: 0.009

Well done. You have MySQL 8.0.16 running on your debian 9 server.

You can as well check our other related guides by following the links below;

Install MySQL 8 on Fedora 30/Fedora 29

Install LAMP Stack on Fedora 30

How To Install LAMP (Linux, Apache, MySQL, PHP) Stack on Fedora 28/29

Install MariaDB 10.3 on CentOS 7

Install MariaDB 10.3 on Fedora 30

Install phpMyAdmin with Apache on Fedora 30


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Jay Decrame
Linux Certified Engineer, Technology and Linux/Unix enthusiast.

Leave a Comment