Installing MySQL on Debian/Ubuntu
In this article I will explain how to install a MySQL server on a Debian/Ubuntu operating system. Starting with Debian 9, when installing the mysql-server package, instead of MySQL, MariaDB is installed (fork of the fully open source MySQL project). Now mysql-server is just an empty transitional metapackage that has already been removed in Debian 10. At the same time, Ubuntu has not yet abandoned MySQL, and the packages still remain on the system. Although MySQL and MariaDB are functionally equivalent and interchangeable, there are differences in functionality. If you need the unique MySQL features from Oracle, then let's proceed with the installation of MySQL.
This instruction was executed on operating systems: Debian 10, Debian 9, Ubuntu 20.10, Ubuntu 20.04, Ubuntu 19.10.
This section can be skipped for Ubuntu.
If your system does not have packages for installing the MySQL server, then you need to add an official repository that will provide .deb packages for installing and managing MySQL. First, let's find out which last package is available for download. Follow the link https://dev.mysql.com/downloads/repo/apt/ and remember the name of the package (its version). Now download this package by running the command in the terminal:
wget -O /tmp/mysql-install.deb https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb
After downloading, install the repository package by running the command in the terminal:
sudo dpkg -i /tmp/mysql-install.deb
During the installation process, select the version of MySQL you need and select the last option "Ok" to save the configuration:
After adding the MySQL repository, we will update the list of packages by running the command in the terminal:
sudo apt-get update
Install the MySQL server by running the command in the terminal:
sudo apt-get install mysql-server
This completes the installation process on Ubuntu.
During the installation process, you will be prompted to set the root password of your MySQL database. Enter a strong password or leave the field blank (for example, for localhost):
If you selected MySQL 8, a notification will appear indicating the use of new authentication based on improved password methods (SHA256). It will be suggested to use strong password encryption or use an outdated authentication method, it is recommended to choose the first option:
Let's check if MySQL is enabled to start automatically when the system is booted by running the command in the terminal (expected result "enabled"):
sudo systemctl is-enabled mysql
Let's check if MySQL is active at the moment by running the command in the terminal (expected result "active"):
sudo systemctl is-active mysql
We can also check the MySQL status with additional information about the service by running the command in the terminal:
sudo systemctl status mysql
If the MySQL server is not installed, an error will be displayed when checking the status:
Let's check if the root user can connect to the MySQL server by running the command in the terminal:
sudo mysql -u root -p
After entering the password, you will see the MySQL shell:
Let's execute a couple of simple queries for testing (getting the current version and displaying the databases):