How to install MySQL server on Debian 9

In this article we will show you how to install Oracle's mysql server to your site instad of MariaDB mysql server.

- Debian 9
- a sudo non-root user

In the latest stable version of Debian, if you ask to install mysql-server, you now get installed mariadb automatically, with no (evident) way of installing Oracle’s MySQL.

Install Oracle’s APT Repositories:

echo -e "deb stretch mysql-5.7\ndeb-src stretch mysql-5.7" | sudo tee /etc/apt/sources.list.d/mysql.list

Before starting to use the repo, you have to add the repo public key as trusted:

sudo wget -O /tmp/RPM-GPG-KEY-mysql
sudo apt-key add /tmp/RPM-GPG-KEY-mysql

If you run apt-key list you will see a new trusted key for apt:

/etc/apt/trusted.gpg -------------------- ...

pub dsa1024 2003-02-03 [SCA] [expires: 2019-02-17] A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5 uid [ unknown] MySQL Release Engineering <>


Refresh your available package list

sudo apt update

Install myqsl-server:

sudo apt install mysql-server

To secure the installation, we can run a simple security script that will ask whether we want to modify some insecure defaults


You will be asked to enter the password you set for the MySQL root account. Next, you will be asked if you want to configure the VALIDATE PASSWORD PLUGIN.

Answer No for disable plugin.

Start and enable (to run after restart) your server:

sudo systemctl start mysql
sudo systemctl enable mysql



We will be happy to hear your thoughts

Leave a reply