MySQL is a relational database management system based on SQL (Structured Query Language). It is one of the most widely used database software for several well-known applications that utilize it. MySQL is used for data warehousing, e-commerce, and logging applications, but its most used feature is web database storage and management.
Debian 11 comes with MySQL in its repository, however as many know, Debian stable provides only security updates for its releases in line with keeping its stable build essentially stable. This has great benefits but some drawbacks; in the tutorial, you will learn how to install MySQL 8 for Debian 11.
- Recommended OS: Debian 11 Bullseye
- User account: A user account with sudo or root access.
- Required packages: wget or curl
Updating Operating System
Update your Debian 11 operating system to make sure all existing packages are up to date:
sudo apt update && sudo apt upgrade
Install WGET package
The tutorial will be using the wget command to install the package using the following command:
sudo apt install wget -y
Note, wget should be installed automatically but run the command to verify if you are unsure.
Import the MySQL Repository
To install the latest version of MySQL, you will need to download and install the MySQL APT .deb repository package that will configure and install the MySQL software repositories on your Debian system.
Use the following command below to download to your TMP folder:
sudo dpkg -i mysql-apt-config_0.8.18-1_all.deb
During the MySQL repository installation, you will see the following pop-up windows:
First, given that Debian 11 stable has just been released at the time of this tutorial, MySQL will inform you it does not support the release. This can be fixed by selecting the old stable release Buster, and this will work fine:
Select Buster and press enter key:
Secondly, you will be asked to confirm what version of MySQL you want to install; for now, it is set up correctly for the latest version, so using the arrow keys, scroll down and select ok to continue:
Select OK to proceed with the installation:
Once done, you will get the following message back in your terminal:
To reflect the new repository, use the apt update command:
sudo apt update
Install MySQL 8
Now that you have completed the import of the repository for MySQL, execute the command to install as follows:
sudo apt install mysql-server
Examples of dependencies that will also be installed:
Type Y, then press enter key to proceed with the installation.
During the installation, a new popup will appear, prompting you to enter the database root password. Make sure this is secure and recorded. Once entered, press the enter key or press tab key to select the <Ok> and hit enter to proceed with the installation:
Note, you will be prompted to re-enter the root password a second time to confirm.
Next, another popup will appear for you to read about the new authentication system.
Next, set the default selection for MySQL for authentication plugin as below:
The installation should finish up after this point. To confirm it has been successfully installed, run the following apt policy command, which will also confirm the current version and build of the MySQL database server:
apt policy mysql-server
Check MySQL 8 server status
The installer will automatically start your MySQL service by default and configure itself to auto-start on system boot. To verify your MySQL service is operational after the installation, type the following systemctl command:
sudo systemctl status mysql
To stop the MySQL service:
sudo systemctl stop mysql
To start the MySQL service:
sudo systemctl start mysql
To disable the MySQL service on system boot:
sudo systemctl disable mysql
To enable the MySQL service on system boot:
sudo systemctl enable mysql
To restart the MySQL service:
sudo systemctl restart mysql
Secure MySQL 8 with Security Script
When installing MySQL fresh, default settings are considered weak by most standards and cause concern for potentially allowing intrusion or exploiting hackers. A solution is to run the installation security script that comes with the MySQL installation.
First, use the following command to launch the (mysql_secure_installation):
You will be prompted to enter your root password, and then you will see a question about VALIDATE PASSWORD COMPONENT; this is to set password complexity checks; for most, the default is fine.
Next, follow below:
- Setting the password for root accounts.
- Removing root accounts that are accessible from outside the local host.
- Removing anonymous-user accounts.
- Removing the test database, which by default can be accessed by anonymous users.
Note, you use (Y) to remove everything. Also, if you like, you can reset your root password by creating a new one; you can skip this if you like as you already set it during the initial installation with the pop-up windows.
Login to MySQL 8 instance
Now that you have completed the post-installation installation security script, login into your MySQL database can be done using the following:
sudo mysql -u root -p
You will be prompted to enter the root password that you set in either the installation setup or post-installation security script. Once inside the MySQL service instance, you can execute the following command as a test to see it in operation.
Type the following SHOW DATABASE command:
For those new to MySQL, all commands must end with “;”
To exit the terminal, type the following exit command:
Uninstall MySQL 8
If you no longer wish to use the MySQL database and want to remove it in full, execute the following command:
sudo apt autoremove mysql-server
Comments and Conclusion
In the tutorial, you have learned how to install the latest MySQL 8. Overall, MySQL 8 has better performance for reading/write workloads, IO-bound workloads, and high contention workloads. In addition, along with options to optimize for specific workloads on specific hardware by mapping user threads to CPUs, to name a few of the new features. Users on older versions of MySQL should consider upgrading, as the performance gains are definitely worth it.