How to Install MySQL 8.0 on Debian 11 Bullseye - LinuxCapable (2023)

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. MySQL is used for data warehousing, e-commerce, and logging applications, but its most used feature is a web database storage and management.

The following tutorial will teach you how to install MySQL Community on Debian 11 Bullseye using the MySQL official APT repository, which will give you the latest version available on your system using the command line terminal.

Table of Contents

Update Debian

First, before proceeding any further, update your system to ensure all existing packages are up to date.

sudo apt update && sudo apt upgrade

Install Required Packages

The tutorial will require the following packages installed. These may be already present as they are very common packages; if unsure, just run the command.

sudo apt install software-properties-common apt-transport-https wget ca-certificates gnupg2 -y

Note, wget should be installed automatically but run the command to verify if you are unsure.

Import the MySQL Community Repository

By default, MySQL 8.0 Community Edition is unavailable on Debian 11’s repository; luckily, a repository exists from the MySQL official repository allowing you to import the latest stable version.

First, import the GPG key using the following command.

sudo wget -O- http://repo.mysql.com/RPM-GPG-KEY-mysql-2022 | gpg --dearmor | sudo tee /usr/share/keyrings/mysql.gpg

Next, import the repository.

echo 'deb [signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/debian bullseye mysql-8.0' | sudo tee /etc/apt/sources.list.d/mysql.list

Users that are using MySQL for development can additionally import the following repositories.

echo 'deb [signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/debian bullseye mysql-tools' | sudo tee -a /etc/apt/sources.list.d/mysql.listecho 'deb-src [signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/debian bullseye mysql-tools' | sudo tee -a /etc/apt/sources.list.d/mysql.list

Lastly, run an APT update.

sudo apt update

Install MySQL

Now that you have completed the import of the repository for MySQL, execute the command to install as follows:

sudo apt install mysql-community-server -y

A new pop-up will appear during the installation, prompting you to enter the database root password. Make sure this is secure and recorded. Once entered, press the enter key or the tab key to select the <Ok> and hit the enter button to proceed with the installation.

Example:

How to Install MySQL 8.0 on Debian 11 Bullseye - LinuxCapable (1)Pin

Note that you will be prompted to re-enter the root password a second time to confirm. REMEMBER THE PASSWORD FOR THE FUTURE!

Next, another pop-up will appear for you to read about the new authentication system.

Select <Ok> to proceed.

Example:

How to Install MySQL 8.0 on Debian 11 Bullseye - LinuxCapable (2)Pin

Next, set the default selection for the authentication plugin as below.

Example:

How to Install MySQL 8.0 on Debian 11 Bullseye - LinuxCapable (3)Pin

The installation should finish up after this point. To confirm it has been installed, run the following apt policy command.

apt policy mysql-community-server

Example output:

How to Install MySQL 8.0 on Debian 11 Bullseye - LinuxCapable (4)Pin

Check the Status of the MySQL

The installer will automatically start your default MySQL service and configure itself to start automatically on system startup.

Verify that your MySQL service is operational after installation; type the followingsystemctl status command.

systemctl status mysql

Example output:

Pin

For new installations, everything should be status ok. Proceed on to securing your MySQL instance.

Below are some of the most common system commands you will require to manage your MySQL systemd service.

Stop the MySQL service:

sudo systemctl stop mysqld

Start the MySQL service:

sudo systemctl start mysqld

Disable the MySQL service at system startup:

sudo systemctl disable mysqld

Activate the MySQL service at system startup:

sudo systemctl enable mysqld

Restart the MySQL service:

sudo systemctl restart mysqld

How to Secure MySQL

When installing MySQL, the new defaults are considered weak by most standards and raise concerns about the potential of allowing intrusion or exploitation by hackers. One solution is to run the installation security script with the MySQL installation.

First, use the following command to launch the (mysql_secure_installation).

sudo mysql_secure_installation

Next, you will be prompted for your root password that was initially set, and then you will see a question about VALIDATE PASSWORD COMPONENT; this involves defining password complexity checks; for the most part, the default is correct.

Then follow below:

  • Setting the password for root accounts.
  • Setting the password for the accounts.
  • Removal of root accounts accessible from outside the localhost.
  • Removal of anonymous user accounts.
  • Removal of the test database, accessible by default to anonymous users.

Be careful; you use (Y) to delete everything. In addition, if you wish, you can reset your root password by creating a new one; you can ignore it if you want, as you already set it during the initial installation with the pop-ups.

Example:

[joshua@debian-11-bullseye ~]$ mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: The existing password for the user account root has expired. Please set a new password.New password: <---- SET NEW PASSWORDRe-enter new password: <---- RE-ENTER NEW PASSWORDRe-enter new password: The 'validate_password' component is installed on the server.The subsequent steps will run with the existing configurationof the component.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) : Y <---- Type Y then press the ENTER KEY (SKIP IF YOU ALREADY JUST SET)New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.Success.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.Success.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY. - Dropping test database...Success. - Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press the ENTER KEY.Success.All done! 

How to Update/Upgrade MySQL

Since you have imported the official APT repository, updating is quick and straightforward; run the following standard APT commands as you would updating any other system package.

sudo apt update && sudo apt upgrade

How to Remove (Uninstall) MySQL

First, stop the database if you no longer want to use the MySQL database.

sudo systemctl stop mysql --now

Use the following command to remove MySQL and any unused dependencies installed.

sudo apt autoremove mysql-community-server

The above command will blanket cover removing dependencies no longer required.

Comments and Conclusion

MySQL Community 8 performs better than the previous module for reading/write workloads, I/O-related workloads, and high contention workloads. Users of older versions of MySQL should consider upgrading, as the performance gains are well worth it.

FacebookTwitterLinkedInPinterestRedditWhatsAppPocketFlipboardHacker News

Similar posts:

  • How to Install WordPress with Nginx, MariaDB, PHP on Debian 11 or 10
  • How to Install phpMyAdmin with Nginx on Debian 11 Bullseye
  • How to Install GitLab on Debian 11 or 10
  • How to Install MariaDB 10.x on Debian 11 or 10
  • How to Install MongoDB 5.0 on Debian 11 Bullseye
  • How to Install MongoDB 6.0 on Debian 11 Bullseye
  • How to Install qBittorrent on Debian 11/10
  • How to Install PostgreSQL on Debian 11 Bullseye
  • How to Install Redis on Debian 11 Bullseye
  • How to Install Git on Debian 12, 11 or 10

References

Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated: 09/19/2023

Views: 6497

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.