How to Install MySQL on Debian 12

MySQL is a Database Management System (DBMS) with basic Structured Query Language (SQL) commands. Web developers often use MySQL when creating applications and websites. It is the most popular open-source database engine. MySQL Database has been developed in close collaboration with users for over 25 years, making it an open-source platform with many features. This means there’s a high chance that MySQL supports your favorite application or programming language. This article will show you how to install MySQL on Debian 12.

Prerequisites

  • Debian 12
  • SSH root access or a regular system user with sudo privileges

Conventions

# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user

Login to the server

First, log in to your Debian 12 server through SSH as the root user:

ssh master@IP_Address -p Port_number

You must replace ‘IP_Address‘ and ‘Port_number‘ with your server’s IP address and SSH port number. Replace ‘master’ with root or your other Debian 12 system user with sudo privileges.

You can check whether you have the proper Debian version installed on your server with the following command:

$ lsb_release -a

You should get this output:

No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm

Before starting, you have to make sure that all Debian 12 OS packages installed on the server are up to date. You can do this by running the following commands:

$ sudo apt update -y

Install MySQL Server

The easiest and most common method of installing a MySQL server is to use apt-get to install it from the default Debian 12 repository. However, Debian 12 ships a MariaDB server as the default SQL server, not MYSQL. If you want to install a MySQL server instead of a MariaDB server, you must first add a MySQL repository.

Add MySQL repository

This is the step we must complete before installing the MySQL server. You must navigate to this download page and click the ‘Download’ button. On the next page, right-click on ‘No thanks, just start my download.’ and copy the download link.

After getting the download link, we can execute this command to download it to our Debian 12 machine.

$ wget https://dev.mysql.com/get/mysql-apt-config_0.8.30-1_all.deb

Next, we can install it by running this command:

$ sudo apt install ./mysql-apt-config_0.8.30-1_all.deb

Replace the downloaded file name if you have a different one. After executing the command above, you will see this on your screen:

Choose MySQL server & Cluster, then hit OK

Install MySQL on Debian

Here, you can choose which MYSQL version you want, choose one, then hit OK

MySQL on Debian 12

Now, the installation will bring you to this step. This time, choose OK as shown in the picture, then select OK at the bottom, and then hit ENTER

Complete Installation

After completing the previous step, we need to refresh the package information on our Debian 12 system by running this command. If you don’t run this command, then you will not be able to install the MySQL server:

$ sudo apt update

That’s it, and you should be able to install the MySQL server now.

$ sudo apt install mysql-server

Follow the instructions on the screen, such as creating a MySQL root password, choosing a strong password, and then waiting for the installation to finish. Make sure to create a strong password that you can remember.

In just a few moments, the MySQL server should be successfully installed and started automatically. It is also configured to run automatically upon server reboot. To verify that MySQL is running, you can run this command:

$ sudo systemctl status mysql

The command will show you an output like this:

● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-06-12 13:59:05 UTC; 53s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 60431 (mysqld)
Status: "Server is operational"
Tasks: 35 (limit: 2251)
Memory: 473.2M
CPU: 684s
CGroup: /system.slice/mysql.service
└─60431 /usr/sbin/mysqld

At this point, you can log in to MySQL shell using the password you created earlier.

$ mysql -u root -p

After hitting the password, it will bring you to the MySQL shell

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 8.4.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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>

You can see on your screen that you have installed MySQL version 8.4.0. At the time you follow this article, the version may be different if you choose another version or use a different mysql-apt-config debian package.

Congratulations! You have followed this article, and now you can install MySQL on Debian 12.

PS. If you liked this post, please share it with your friends or leave a comment below.

Leave a Comment