Install MySQL on Debian 9 Stretch - Step by Step Process ?

MySQL is most popular open-source database management system. MySQL is no longer available with release of Debian 9 and MariaDB has become the default database system. Commonly, MySQL is being a part of the popular LAMP and LEMP stacks.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related MySQL queries.

In this context, we shall look into how to install MySQL on Debian 9 server from the MySQL apt repository.


How to Configure MySQL PPA ?

Before proceeding with MySQL installation procedure, ensure that you are using a user account with sudo privileges.

MySQL provides official MySQL PPA for Debian system. So we will download MySQL package from there and install on Debian system. Run below command to enable PPA repository:

$ wget http://repo.mysql.com/mysql-apt-config_0.8.12-1_all.deb

Once the download is completed then you can install the release package using below command:

$ sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb

It will prompt you to configuration menu where you can select MySQL version whatever you want.

By default, MySQL 8.0 is selected. You can install another version by selecting MySQL Server & Cluster (Currently selected: mysql-8.0) option and choose version as per your requirement. 

Here, we will install MySQL 8.0 so select the last option OK and hit Enter key to save changes.


How to Install MySQL on Debian ?

Now your server is ready to install MySQL. 

Start by updating the package list using:

$ sudo apt update

Use the below command to install MySQL server on your Debian system:

$ sudo apt install mysql-server

You will be prompted to set root user password as below. Enter a strong password for root user and hit Ok button. Again, It will ask to re-enter password. This password will be use as root user password.

Next, you will be presented with a message informing you about the new MySQL 8 authentication.

After that, it will prompt with a message informing you about the new MySQL 8 authentication. Before selecting the default MySQL 8 authentication plugin make sure it is supported by your application.


How to Verify MySQL installation ?

MySQL service will start automatically once the installation is completed. You can check the MySQL service status by typing:

$ sudo systemctl status mysql

It should show below output if service active:

Output
● mysql.service - MySQL Community Server
    Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
    Active: active (running) since Tue 2019-04-23 10:37:09 IST; 13s ago
      Docs: man:mysqld(8)
            http://dev.mysql.com/doc/refman/en/using-systemd.html
   Process: 4475 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=
  Main PID: 4510 (mysqld)
    Status: "SERVER_OPERATING"
     Tasks: 38 (limit: 4915)
    CGroup: /system.slice/mysql.service
            └─4510 /usr/sbin/mysqld


How to Secure MySQL Installation ?

You can improve MySQL security by execute the mysql_secure_installation command. It's a MySQL inbuilt security script. 

Run then below command:

$ sudo mysql_secure_installation

Once you execute this command it will prompt you to enter root user password which you set before this step.

After that, it will ask you to choose whether to use the VALIDATE PASSWORD PLUGIN or not, which can be used to test the strength of your MySQL password. Press ENTER if you don't want to set up the validate password plugin.

Next, It will ask if you want to change current root user password. If your current password is perfect then, enter N for "no" at the prompt.

Now, for all next questions press Y and hit Enter key for each. This will remove some anonymous users and test database, disable remote root logins and load these new rules so that MySQL immediately respects the changes you have made.

Following questions will be prompted and you have to press yes/y for all :

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y


How to Connect to MySQL from the command line ?

You can login to MySQL server using command line using below command:

$ mysql -u root -p

You will be prompted to enter root user password which you set before and it will show you output as below:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.15 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
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

[Need to fix MySQL errors? We can help you. ]

This article covers how to install mysql 8.0 and Secure MySQL on Debian 9 server. MySQL, the world's most popular open-source relational database management system is not available in the default Debian's repositories. MariaDB is the default database system in Debian 10. 

The MySQL APT repository provides a simple and convenient way to install and update MySQL products with the latest software packages using Apt. The MySQL APT repository provides MySQL packages for the following Linux distros: Debian.


How to Uninstall MySQL from Debian?

To remove MySQL, Run the following commands:

$ sudo apt-get remove --purge mysql-server mysql-client mysql-common -y
$ sudo apt-get autoremove -y
$ sudo apt-get autoclean
rm -rf /etc/mysql
sudo find / -iname 'mysql*' -exec rm -rf {} \;


How to secure MySQL ?

MySQL comes with a command we can use to perform a few security-related updates on our new install. Let's run it now:

$ mysql_secure_installation

This will ask you for the MySQL root password that you set during installation. Type it in and press ENTER. Then answer a series of yes or no prompts. 

Related Posts