How to Install MySQL on Debian 13

If your application requires MySQL, the database package name on Debian 13 can be misleading. Debian’s default-mysql-server package
installs MariaDB. You can install MySQL Community Server from Oracle’s APT repository.
This guide covers installing MySQL 8.4 LTS on Debian 13 Trixie, restricting it to local connections, and creating a database and user for your application.
Prerequisites
You will need a fresh Debian 13 system with a user that has sudo privileges
. Oracle publishes MySQL server packages for Debian 13 on amd64 (64-bit Intel and AMD). Run dpkg --print-architecture to check your system.
If you already run MySQL or MariaDB on this system, back up your databases and review Oracle’s migration guidance before proceeding. Replacing MariaDB requires a separate migration.
Adding the MySQL APT Repository
Update the package index and install curl and the CA certificates it needs for HTTPS:
sudo apt update
sudo apt install ca-certificates curlDownload the configuration package from the MySQL APT Repository page
or use curl:
curl -fLO https://dev.mysql.com/get/mysql-apt-config_0.8.40-1_all.debInstall the downloaded package with APT so it can install the prerequisites. If Oracle offers a newer configuration package, use its filename in the command:
sudo apt install ./mysql-apt-config_0.8.40-1_all.debIn the configuration menu, the MySQL Server & Cluster entry already shows mysql-8.4-lts, the default series. Select Ok to keep it. The menu also offers mysql-9.7-lts, a newer long-term support series. Choose it only if your application supports MySQL 9.7.
Update the package index and check the candidate version before installing:
sudo apt update
apt-cache policy mysql-serverLook for an 8.4 candidate from the trixie/mysql-8.4-lts repository. APT uses the selected series for subsequent package upgrades.
Restricting MySQL to Local Connections
Oracle’s package starts MySQL automatically. By default, both the classic MySQL listener on port 3306 and the X Protocol listener on port 33060 listen on all interfaces. Configure both to bind to 127.0.0.1 before the first startup:
sudo install -d /etc/mysql/mysql.conf.d
sudo tee /etc/mysql/mysql.conf.d/local-only.cnf >/dev/null <<'EOF'
[mysqld]
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
EOFThe package reads this file alongside its supplied configuration. Applications on the server can still connect through the Unix socket or loopback.
Installing MySQL Server
Install the MySQL server package:
sudo apt install mysql-serverWhen prompted for the MySQL root password, choose a strong password and store it securely. You can also leave the password blank to use auth_socket, which authenticates the local operating-system root user over the Unix socket.
After installation, verify the service is running:
systemctl is-active mysqlactiveAn active result confirms the service is running. Check the addresses for both TCP listeners with ss:
ss -ltn '( sport = :3306 or sport = :33060 )'The Local Address:Port column should show 127.0.0.1:3306 and 127.0.0.1:33060. To reach this server from another machine, you can connect through an SSH tunnel
.
Securing the Installation and Connecting
If you set a root password, run the MySQL hardening utility and enter that password when prompted:
mysql_secure_installationThe utility can enable the password validation component. If you enable it, select 1 for MEDIUM, which requires at least eight characters, including mixed case, digits, and special characters. Keep the password you just set if it already meets the policy. On this fresh installation, answer Y to remove anonymous accounts, disallow remote root logins, remove the test database if present, and reload the privilege tables.
When the utility finishes, open the MySQL shell with the root password:
mysql -u root -pIf you left the installer password blank, use the Unix socket to open the MySQL shell:
sudo mysqlWith socket authentication, you can skip the utility and verify the initial accounts and databases directly. At the mysql> prompt, run:
SELECT User, Host, plugin FROM mysql.user WHERE User IN ('root', '');
SHOW DATABASES LIKE 'test';On a clean socket-authenticated installation, the first query should return only root@localhost with the auth_socket plugin, and the second should return an empty set.
Creating a Database and User
At the mysql> prompt, create a database and a dedicated local user. MySQL generates a password for the new account and displays it in the result:
CREATE DATABASE appdb CHARACTER SET utf8mb4;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'appuser'@'localhost';Save the generated password in a password manager or your application’s secret store. Keep local .env files containing credentials out of version control with .gitignore.
The example grants read and write access to rows in appdb. If your application manages its own schema, grant the extra privileges it needs
or use a separate account for migrations.
Exit the MySQL shell with exit, then test the new account from the terminal:
mysql -u appuser -p appdbEnter the generated password. At the mysql> prompt, confirm which account and database the connection is using:
SELECT CURRENT_USER(), DATABASE();The result should show appuser@localhost and appdb.
Troubleshooting
Package ‘mysql-server’ has no installation candidate
Oracle publishes Debian 13 packages for amd64 only. On other architectures, sudo apt update prints Skipping acquire of configured file ... doesn't support architecture 'arm64'. APT may then suggest mariadb-server, which installs MariaDB, not MySQL. On amd64, run sudo dpkg-reconfigure mysql-apt-config, select mysql-8.4-lts, then run sudo apt update and resolve any repository errors before retrying.
Access denied for user ‘root’@’localhost’ERROR 1698 means root uses socket authentication: log in with sudo mysql. ERROR 1045 ... (using password: NO) means you set a root password: log in with mysql -u root -p.
MySQL does not start after a configuration change
Run sudo mysqld --validate-config to check the option files. If the check passes, look for the startup error with sudo journalctl -u mysql -n 50 and sudo tail -n 50 /var/log/mysql/error.log.
Access denied for application user
Test with the same transport and credentials the application uses. The example login uses the Unix socket and matches 'appuser'@'localhost'. An explicit -h 127.0.0.1 uses TCP, and MySQL may match a different account depending on its host settings.
Conclusion
Configure your application to use appdb and the credentials for appuser. Once the database holds application data, see how to back up and restore MySQL databases with mysqldump
.
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page