How to install MySQL 8.4 on Ubuntu and Debian

Install MySQL on Ubuntu or Debian from the distribution packages or the official MySQL APT repository, secure it and make your first connection.

  • Beginner
  • Linux VPS
  • 4 min read

By RunRacks Team · Published

MySQL is the database behind a large share of web apps, from WordPress to custom PHP and Node.js projects. This guide shows the two ways to install it on Ubuntu and Debian, how to lock down the default install, and how root logs in on a fresh server.

Before you start

  • A RunRacks Linux VPS running Ubuntu 22.04 or 24.04, or Debian 12.
  • A user with sudo rights, connected over SSH. Your login details are in the Dashboard.
  • No other database server on port 3306. If MariaDB is already installed, do not install MySQL alongside it.

Choose where to install from

You have two sources:

  • Ubuntu's own packages. Ubuntu 22.04 and 24.04 ship MySQL 8.0 as mysql-server. It is the simplest option and gets security updates through normal apt upgrade. It is not 8.4.
  • The official MySQL APT repository. Oracle publishes this repository so you can pick a release series, including MySQL 8.4 LTS. Use it when you want 8.4 on Ubuntu, or MySQL at all on Debian 12.

Option 1: install from Ubuntu packages

Terminal
sudo apt update
sudo apt install mysql-server

The service starts on its own. Skip to Secure the install.

Option 2: install MySQL 8.4 from the MySQL APT repository

  1. Open the MySQL APT repository download page at dev.mysql.com/downloads/repo/apt/ in your browser and copy the link to the current mysql-apt-config .deb file. The file name includes a version number that changes over time, so always use the current link.
  2. Download and install it on the server, replacing the URL with the one you copied:
Terminal
   cd /tmp
   wget https://dev.mysql.com/get/mysql-apt-config_X.Y.Z-1_all.deb
   sudo apt install ./mysql-apt-config_X.Y.Z-1_all.deb
  1. A text menu opens. Select MySQL Server & Cluster, choose the mysql-8.4-lts series, then choose Ok to save.
  2. Install the server:
Terminal
   sudo apt update
   sudo apt install mysql-server
  1. The installer asks for a root password. Choose your own long, unique password and keep it in a password manager.

Check the version you got:

Terminal
mysql --version

The output should mention 8.4. If it shows 8.0, apt picked Ubuntu's package; run apt policy mysql-server to see which repository won.

Secure the install

MySQL ships a script that removes test data and tightens defaults:

Terminal
sudo mysql_secure_installation

Answer the prompts:

  • VALIDATE PASSWORD component: optional. It rejects weak passwords for new accounts. Turn it on if several people create users.
  • Remove anonymous users: yes.
  • Disallow root login remotely: yes.
  • Remove test database: yes.
  • Reload privilege tables: yes.

How root logs in

How root authenticates depends on where MySQL came from.

  • Ubuntu packages: root@localhost uses the auth_socket plugin. It does not use a password at all. Instead, MySQL checks that the Linux user running the client is root. You log in with:
Terminal
  sudo mysql

This is secure by design: only someone with sudo on the server can get in as MySQL root.

  • MySQL APT repository: root uses the password you chose during install:
Terminal
  mysql -u root -p

Check which plugin root uses:

SQL
SELECT user, host, plugin FROM mysql.user WHERE user = 'root';

auth_socket means sudo mysql; caching_sha2_password means a password login.

Check it works

Confirm the service is running and enabled at boot:

Terminal
systemctl status mysql
sudo systemctl is-enabled mysql

You should see active (running) and enabled. Then check MySQL only listens locally:

Terminal
sudo ss -ltnp | grep 3306

A line showing 127.0.0.1:3306 means only local apps can connect. Finally, run a query:

Terminal
sudo mysql -e "SELECT VERSION();"

Troubleshooting

  • `ERROR 1698 (28000): Access denied for user 'root'@'localhost'`: root uses auth_socket. Run sudo mysql instead of mysql -u root -p.
  • `ERROR 1045 Access denied` with a password: the password is wrong or you are logging in as the wrong account. Use sudo mysql if root uses auth_socket.
  • Service fails to start: read sudo journalctl -u mysql -n 50 and /var/log/mysql/error.log. A leftover MariaDB install or a bad config line is the usual cause.
  • apt installs 8.0 instead of 8.4: the MySQL repository was not added or not selected. Rerun sudo dpkg-reconfigure mysql-apt-config and sudo apt update.
  • Out-of-memory restarts on a small VPS: add a swap file or move to a larger plan.

Next steps

Was this guide helpful?

Still stuck?

Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.

Databases

Reset a Forgotten MySQL Root Password on Linux

Recover access to MySQL or MariaDB on a Linux VPS by starting the server with skip-grant-tables, setting a new root password and restarting normally.

  • Intermediate
  • Linux VPS
  • 5 min read

Databases

MySQL Point-in-Time Recovery Using Binary Logs

Recover a MySQL or MariaDB database to an exact moment after a bad write or dropped table by restoring a full backup and replaying binary logs up to the incident.

  • Advanced
  • Linux VPS
  • 7 min read