Info2soft use cookies to help you have a superior and more admissible browsing experience on our website. Privacy Policy
Loading...
Debian’s default repositories may provide MariaDB instead of Oracle MySQL, which can be a concern for applications that require the official MySQL database engine. This guide explains how to install MySQL on Debian 12 (Bookworm) and Debian 13 (Trixie) using the official MySQL APT repository.
You will learn how to configure the repository, install MySQL Server, verify the installation, and complete essential security configurations to prepare your database environment.
If you run apt install mysql-server on Debian, the package manager may install MariaDB instead of MySQL. This happens because Debian now uses MariaDB as the default MySQL-compatible database option in its repositories.
MariaDB vs MySQL: What You Should Know
MariaDB and MySQL share a common origin and are highly compatible, but they are now developed as separate database systems. If your application requires a specific MySQL version or features, you should install MySQL from the official MySQL APT repository instead.
How to Check Your Installed Database Server
Use the following command to check which database engine is currently installed:
mysql --version
You can also check installed packages with:
dpkg -l | grep -E "mysql-server|mariadb-server"
These commands help confirm whether your Debian system is running Oracle MySQL or MariaDB before continuing with the installation process.
Installing MySQL on Debian involves several steps, including preparing your system, selecting the right installation source, installing MySQL Server, and completing the initial configuration. Before starting the installation, complete the following prerequisites to ensure a smooth setup.
Before installing MySQL on Debian,
To check your Debian version, run:
cat /etc/os-release
Find the VERSION_CODENAME or VERSION field in the output. This information helps ensure you use the correct repository configuration during the installation process.
Debian’s default repositories may provide MariaDB instead of Oracle MySQL. If your application requires a specific MySQL version, Oracle MySQL features, or compatibility with existing MySQL environments, use the official MySQL APT repository.
The MySQL APT repository allows you to install supported MySQL versions, including MySQL 8.4 LTS, directly from the official source.
Before installing MySQL, update your package index and upgrade existing packages to ensure your system has the latest dependencies.
Run:
sudo apt update
sudo apt upgrade -y
Install the required utilities for managing external repositories:
sudo apt install -y wget gnupg lsb-release
The official MySQL APT repository allows you to install Oracle MySQL packages instead of relying on the default Debian repositories.
Download the MySQL APT repository configuration package:
cd /tmp
wget https://dev.mysql.com/get/mysql-apt-config_0.8.32-1_all.deb
Install the repository configuration package:
sudo dpkg -i mysql-apt-config_0.8.32-1_all.deb
During the configuration process:
After the repository is configured, update your package index:
sudo apt update
Install MySQL Server from the configured MySQL repository:
sudo apt install -y mysql-server
During installation, MySQL may prompt you to configure the root authentication method depending on your package version. For MySQL 8.x, caching_sha2_password is the recommended authentication plugin because it provides stronger security than the legacy authentication method.
After installation, check that the MySQL service is running:
sudo systemctl status mysql
Enable MySQL to start automatically after reboot:
sudo systemctl enable mysql
A default MySQL installation may contain settings that are not suitable for production environments. Use the built-in security script to remove unnecessary access and improve the server configuration.
Run:
sudo mysql_secure_installation
The script helps you:
You can also enable the Validate Password Component to enforce stronger password policies if required.
Applications should avoid connecting to MySQL with the root account. Instead, create a dedicated database user with only the required permissions.
Log in to MySQL:
sudo mysql -u root -p
Create a database and user:
CREATE DATABASE app_database;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'YourStrongAndUniquePassword123!';
GRANT ALL PRIVILEGES ON app_database.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Using separate database users improves security and makes permission management easier.
Step 6: Enable Remote Access (Optional)
By default, MySQL only accepts local connections. If your application connects from another server, configure MySQL to listen for external connections.
Open the MySQL configuration file:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Find the bind-address setting and update it:
bind-address = 0.0.0.0
Alternatively, specify a private IP address to allow connections only from a trusted network.
Restart MySQL to apply the changes:
sudo systemctl restart mysql
Avoid exposing MySQL directly to the public internet. Use firewall rules, such as ufw or nftables, to restrict access to trusted IP addresses only.
Removing MySQL from Debian requires more than uninstalling the packages. A complete removal may also include deleting configuration files, repository settings, and database files.
First, stop the MySQL service:
sudo systemctl stop mysql
Remove the installed MySQL packages and configuration files:
sudo apt purge -y mysql-server mysql-client mysql-common mysql-apt-config
Clean up unused dependencies:
sudo apt autoremove -y
If you added the official MySQL APT repository, remove its repository configuration before updating package lists:
sudo rm -f /etc/apt/sources.list.d/mysql.list
sudo apt update
If you want to completely remove all databases, logs, and MySQL configuration files, delete the remaining data directories:
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql
Even with the correct installation steps, you may encounter issues related to authentication, services, package conflicts, or remote connections. The following solutions cover some of the most common MySQL installation problems on Debian.
This error usually occurs when the root account is configured to authenticate through the operating system instead of a password.
Try logging in with administrative privileges:
ssudo mysql -u root
If you want to use password authentication for the root account, update the authentication method from the MySQL shell:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'YourNewStrongPassword';
FLUSH PRIVILEGES;
Note that changing the root authentication method is optional. For many Debian environments, socket-based authentication provides a secure local administration method.
If MySQL fails to start, check the service logs first to identify the root cause:
sudo journalctl -u mysql -n 50 --no-pager
Common causes include permission issues, insufficient system resources, or another database service already using port 3306.
Check whether another process is using the MySQL port:
sudo ss -tulpn | grep 3306
Stop conflicting services before restarting MySQL.
Installing MySQL after MariaDB has been previously configured may cause package conflicts due to overlapping files or dependencies.
Before removing existing database packages, confirm that you no longer need the current MariaDB installation. If you are setting up a clean server, remove the conflicting packages:
sudo apt purge mariadb-server mariadb-client
sudo apt autoremove -y
Then run the MySQL installation process again.
This error means the MySQL server is reachable, but the user account does not have permission to connect from the remote host.
First, verify that MySQL accepts external connections by checking the bind-address setting:
/etc/mysql/mysql.conf.d/mysqld.cnf
Then create or update a database user with the correct host permission:
CREATE USER 'app_user'@'remote_ip' IDENTIFIED BY 'YourStrongPassword';
GRANT ALL PRIVILEGES ON app_database.* TO 'app_user'@'remote_ip';
FLUSH PRIVILEGES;
Using % as the host allows connections from any IP address, which may be acceptable for testing but should be restricted in production environments.
Once MySQL is up and running, it’s easy to move on and forget about backups until something goes wrong. But an unprotected database is one bad DROP TABLE, failed disk, or botched upgrade away from becoming a real problem.
This is where a dedicated backup MySQL database solution like i2Backup becomes worth considering. It handles the scheduling, storage, and recovery process so backups don’t depend on someone remembering to run a script.
i2Backup comes with several features relevant to a MySQL deployment like the one covered in this guide:
Setting up MySQL is the first step. Making sure that data can be recovered after a failure is what keeps a database server production-ready. If you’re looking for a backup solution that goes beyond ad hoc dump scripts, Info2soft also offers i2CDP for near-zero RPO continuous data protection, and i2Availability for businesses that need automatic failover on top of backup coverage.
Q1: Does Debian 12 support MySQL 8?
Yes. Debian 12 can run MySQL 8.x, including MySQL 8.0 and MySQL 8.4 LTS, when installed through the official MySQL APT repository. This allows you to install and manage Oracle MySQL packages directly instead of relying on Debian’s default database packages.
Q2: Can I install MySQL and MariaDB side by side?
Yes, but running both database systems on the same host requires careful configuration. They may conflict because they use similar package names, configuration paths, and the default MySQL port (3306).
For testing or development environments, using separate containers is often the simplest approach.
Q3: How do I check my installed MySQL version?
Run the following command:
mysql --version
You can also check the exact server version from the MySQL command line:
SELECT VERSION();
Q4: Is MySQL free to use on Debian?
MySQL Community Server is available under the GNU General Public License (GPL) and can be used for many development and production deployments. However, some enterprise features and commercial offerings require separate licensing.
Debian’s default repository installs MariaDB, not MySQL, so adding the official MySQL APT repository is the reliable way to get the real thing on Debian 12 or 13. From setup and security to remote access and troubleshooting, this guide covers what’s needed to get MySQL running cleanly.
Once MySQL is up, protecting the data inside it matters just as much as the install itself. Info2soft‘s i2Backup handles that side, so backups don’t depend on remembering to run a script.