How to Install MySQL 8.4 on Ubuntu 26.04, 24.04 and 22.04

Last updated Wednesday, May 6, 2026 2:16 pm Joshua James 9 min read

MySQL 8.4 LTS is the branch to choose on Ubuntu when your application stack needs MySQL 8.4 compatibility instead of Ubuntu’s older MySQL 8.0 packages or Oracle’s newer 9.7 LTS line. Ubuntu 26.04 already includes MySQL 8.4 in its default APT sources, while Ubuntu 24.04 and 22.04 need Oracle’s MySQL APT repository locked to the mysql-8.4-lts component. That split matters for WordPress, Laravel, phpMyAdmin, and other PHP on Ubuntu deployments that rely on a stable MySQL server branch.

Fresh MySQL 8.4 installs on Ubuntu 26.04, 24.04, and 22.04 start with the release-specific package source, and upgrades from MySQL 8.0 to 8.4 on Ubuntu 24.04 or 22.04 need a backup first. MariaDB is not a drop-in replacement target here; if MariaDB is already installed, back up and plan that migration before replacing packages.

Install MySQL 8.4 on Ubuntu

Start by matching your Ubuntu release to the correct source. If you are unsure which release you are running, check it first with the Ubuntu version command guide.

Ubuntu ReleaseDefault MySQL PackageMySQL 8.4 PathUse This When
Ubuntu 26.04 LTSMySQL 8.4.xInstall from Ubuntu’s default APT sourcesYou want the Ubuntu-packaged 8.4 branch without adding a vendor repository
Ubuntu 24.04 LTSMySQL 8.0.xAdd Oracle’s MySQL APT repository with mysql-8.4-ltsYou need MySQL 8.4 on Noble instead of the default 8.0 branch
Ubuntu 22.04 LTSMySQL 8.0.xAdd Oracle’s MySQL APT repository with mysql-8.4-ltsYou need MySQL 8.4 on Jammy and have checked application compatibility

Oracle’s MySQL APT repository currently publishes Ubuntu 24.04 and 22.04 metadata for MySQL 8.4 LTS, but not an Ubuntu 26.04 resolute repository path. On Ubuntu 26.04, use the Ubuntu package unless Oracle later adds a supported 26.04 repository.

Oracle now also publishes MySQL 9.7 LTS in the same repository family. These repository commands intentionally keep the source on mysql-8.4-lts so readers who searched for MySQL 8.4 do not accidentally move to a newer LTS branch. For the release-track background, see Oracle’s MySQL LTS and Innovation release model.

MySQL LTS branches are built for stable behavior across a longer maintenance window: Oracle’s LTS policy provides 5 years of premier support and 3 years of extended support for each LTS series. Innovation releases are production-grade too, but they move faster and are supported only until the next Innovation release. That is why the Oracle source is pinned to mysql-8.4-lts instead of using the broader Innovation track.

If you only need Ubuntu’s default MySQL 8.0 packages on Ubuntu 24.04 or 22.04, use the MySQL 8.0 installation guide for Ubuntu instead of adding Oracle’s 8.4 repository.

The main install path installs MySQL Server and the classic mysql client. MySQL Shell is a separate administration tool that uses the mysqlsh command and is published on Oracle’s MySQL Shell download page.

Refresh Ubuntu Packages Before Installing MySQL

Update your package index before installing or adding a new repository. This keeps dependency resolution current and avoids stale package metadata during the MySQL install.

sudo apt update
sudo apt upgrade

These commands use sudo. If your account cannot run administrative commands, add the user to sudoers first with the Ubuntu sudoers guide.

Option 1: Install MySQL 8.4 from Ubuntu Packages on 26.04

Ubuntu 26.04 ships MySQL 8.4 in the main repository. Confirm the candidate first if you want to verify that APT is using the Ubuntu package source.

apt-cache policy mysql-server

Relevant output on Ubuntu 26.04 includes:

mysql-server:
  Installed: (none)
  Candidate: 8.4.8-0ubuntu1
  Version table:
     8.4.8-0ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu resolute/main amd64 Packages

Install the server package after the candidate shows an 8.4.x build from the Ubuntu repository.

sudo apt install mysql-server

Ubuntu’s package starts the service automatically and normally lets the local root account connect through socket authentication. After installation, verify the client version:

mysql --version

Expected output pattern:

mysql  Ver 8.4.x for Linux on x86_64 (Ubuntu)

Option 2: Install MySQL 8.4 from Oracle on 24.04 or 22.04

Ubuntu 24.04 and 22.04 default to MySQL 8.0 packages. To install MySQL 8.4 on those releases, add Oracle’s MySQL APT repository and select the 8.4 LTS component. Oracle documents the repository family in the MySQL APT repository guide, and the MySQL APT download page lists both MySQL 8.4 LTS and newer MySQL LTS branches.

Install Repository Prerequisites

Install the small set of packages needed to download the signing key and create the repository file.

sudo apt install -y ca-certificates curl gpg

Import the MySQL APT Signing Key

MySQL’s current APT key ID is B7B3B788A8D3785C. Import it through Ubuntu’s keyserver, then store the dearmored keyring under /usr/share/keyrings. The curl command guide explains the flags used for remote file downloads.

curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xb7b3b788a8d3785c" | gpg --dearmor | sudo tee /usr/share/keyrings/mysql.gpg > /dev/null

Verify the imported fingerprint before trusting the repository.

gpg --show-keys --with-fingerprint /usr/share/keyrings/mysql.gpg

Expected key identity:

pub   rsa4096 2023-10-23 [SC] [expires: 2027-10-23]
      BCA4 3417 C3B4 85DD 128E  C6D4 B7B3 B788 A8D3 785C
uid                      MySQL Release Engineering <mysql-build@oss.oracle.com>

Create the MySQL 8.4 Repository Source

Create a DEB822 source file for MySQL 8.4 LTS. The guard stops on Ubuntu 26.04 because Oracle does not publish resolute metadata for this component. The verified Oracle repository metadata for Ubuntu 24.04 and 22.04 publishes amd64 packages, so this example targets standard amd64 Ubuntu systems.

. /etc/os-release
case "$VERSION_CODENAME" in
  noble|jammy) ;;
  *) echo "Oracle does not publish MySQL 8.4 LTS packages for $VERSION_CODENAME."; exit 1 ;;
esac

printf '%s\n' \
  "Enabled: yes" \
  "Types: deb" \
  "URIs: https://repo.mysql.com/apt/ubuntu" \
  "Suites: $VERSION_CODENAME" \
  "Components: mysql-8.4-lts" \
  "Architectures: amd64" \
  "Signed-By: /usr/share/keyrings/mysql.gpg" | sudo tee /etc/apt/sources.list.d/mysql.sources > /dev/null

Confirm the file points to your Ubuntu codename.

cat /etc/apt/sources.list.d/mysql.sources

Ubuntu 24.04 example:

Enabled: yes
Types: deb
URIs: https://repo.mysql.com/apt/ubuntu
Suites: noble
Components: mysql-8.4-lts
Architectures: amd64
Signed-By: /usr/share/keyrings/mysql.gpg

Ubuntu 22.04 should show Suites: jammy. If you see resolute on Ubuntu 26.04, stop and use Option 1 instead because Oracle does not currently publish that repository path.

Refresh APT and Confirm the MySQL 8.4 Candidate

Refresh APT after adding the source, then check the final package candidate before installing.

sudo apt update
apt-cache policy mysql-server

APT fetch numbering and byte counts vary, but the update should mention https://repo.mysql.com/apt/ubuntu noble InRelease on Ubuntu 24.04 or jammy InRelease on Ubuntu 22.04. The candidate check should then show the MySQL 8.4 source:

mysql-server:
  Installed: (none)
  Candidate: 8.4.9-1ubuntu24.04
  Version table:
     8.4.9-1ubuntu24.04 500
        500 https://repo.mysql.com/apt/ubuntu noble/mysql-8.4-lts amd64 Packages
     8.0.45-0ubuntu0.24.04.1 500
        500 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages

Ubuntu 22.04 should show the same MySQL 8.4 branch with a package suffix such as 8.4.9-1ubuntu22.04 from jammy/mysql-8.4-lts.

Install MySQL 8.4 Server

Install the standard mysql-server package. With the MySQL source enabled, APT resolves it to Oracle’s MySQL 8.4 packages.

sudo apt install mysql-server

The MySQL Community package prompts for a root password and asks which authentication plugin to use. Choose the strong password encryption option unless you maintain legacy applications that cannot use caching_sha2_password.

Verify the installed client version after APT finishes.

mysql --version

Expected output pattern:

mysql  Ver 8.4.x for Linux on x86_64 (MySQL Community Server - GPL)

After installation, consider installing phpMyAdmin on Ubuntu only when you need web-based database administration. If MySQL listens beyond localhost, configure UFW firewall rules on Ubuntu so port 3306/tcp is restricted to trusted application hosts.

Upgrade MySQL 8.0 to MySQL 8.4 on Ubuntu

Ubuntu 24.04 and 22.04 users often reach this page while upgrading from the distro-provided MySQL 8.0 packages. Treat that as a database upgrade, not just a package refresh. Back up first, test application compatibility, and schedule downtime for applications that write to the database.

sudo mysqldump --all-databases --single-transaction --routines --triggers > ~/mysql-before-8-4-$(date +%F).sql

If your root account uses password authentication, add -u root -p to the command and enter the password when prompted. Store the backup somewhere safe before changing packages.

After adding the MySQL 8.4 repository from Option 2, run a simulation so you can see whether APT plans to replace MySQL packages or remove a conflicting MariaDB installation.

apt-get -s install mysql-server

If the simulation looks correct, perform the upgrade with Oracle’s recommended package name.

sudo apt install mysql-server

Do not force a MariaDB-to-MySQL replacement from a simulation that lists MariaDB removals or dependency conflicts unless you have a tested migration plan. Oracle’s MySQL APT documentation warns that MySQL forks need their own uninstall and backup path before MySQL packages are installed.

Manage the MySQL 8.4 Service

MySQL installs a mysql systemd service. Use these commands for routine service management.

TaskCommand
Check active statesystemctl is-active mysql
Check boot statesystemctl is-enabled mysql
Start MySQLsudo systemctl start mysql
Stop MySQLsudo systemctl stop mysql
Restart MySQLsudo systemctl restart mysql
Enable startupsudo systemctl enable mysql
Disable startupsudo systemctl disable mysql

Confirm that MySQL is running and enabled.

systemctl is-active mysql
systemctl is-enabled mysql

Successful output:

active
enabled

Use the login method that matches your install source. Ubuntu’s 26.04 package commonly uses socket authentication for the local root account:

sudo mysql -e "SELECT VERSION();"

For Oracle’s MySQL Community packages, use the password you set during installation:

mysql -u root -p -e "SELECT VERSION();"

Expected output pattern:

VERSION()
8.4.x

Secure MySQL 8.4 After Installation

Run MySQL’s security helper after the service starts. It removes weak defaults such as anonymous users, remote root logins, and the test database.

sudo mysql_secure_installation

Answer the prompts according to your environment. For new servers, the usual choices are to set or keep a strong root password, remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables. If Ubuntu’s socket-authenticated root account skips the root password prompt, that is expected; you can still remove the unsafe defaults.

Do not use mysql_native_password for new deployments. MySQL 8.4 favors caching_sha2_password, and older authentication plugins can fail when newer clients or servers stop loading legacy plugin support.

Update or Remove MySQL 8.4

Update MySQL 8.4 Packages

Use a targeted APT refresh when you only want to update MySQL packages. On Oracle’s repository path, running sudo apt install mysql-server after apt update keeps the selected MySQL 8.4 LTS branch current.

sudo apt update
sudo apt install mysql-server

System-wide apt upgrade is fine for normal Ubuntu maintenance, but do not assume unattended-upgrades handles Oracle’s third-party repository unless you have explicitly configured and verified that origin in your automation policy.

Remove MySQL 8.4 Packages

Back up databases before removing packages. This command exports all databases with routines and triggers.

sudo mysqldump --all-databases --single-transaction --routines --triggers > ~/mysql-backup-$(date +%F).sql

Stop the service before removing server packages.

sudo systemctl stop mysql

If you installed MySQL 8.4 from Ubuntu 26.04 default packages, purge the Ubuntu package names.

sudo apt purge mysql-server mysql-client mysql-server-core mysql-client-core mysql-common

If you installed from Oracle’s MySQL APT repository, purge the MySQL Community packages instead.

Oracle’s package removal may ask whether to delete the MySQL data directory. Keep the data unless your backup is verified and you are ready for permanent deletion; the optional data cleanup later handles that step explicitly.

sudo apt purge mysql-server mysql-client mysql-community-server mysql-community-client mysql-community-server-core mysql-community-client-core mysql-community-client-plugins mysql-common

APT may still mark dependency packages as autoremovable. Preview that cleanup list before confirming it, especially on reused servers or desktops where unrelated packages may already be marked for removal.

sudo apt autoremove --purge --dry-run

If the preview lists only MySQL-related packages you no longer need, run the cleanup.

sudo apt autoremove --purge

Confirm that no MySQL server packages remain installed.

dpkg -l 'mysql-server*' 'mysql-client*' 'mysql-community-server*' 'mysql-community-client*' | grep '^ii' || echo 'No installed MySQL server or client packages remain.'

If you used Oracle’s repository and no longer need any Oracle MySQL APT components, remove the source and keyring created earlier.

sudo rm -f /etc/apt/sources.list.d/mysql.sources
sudo rm -f /usr/share/keyrings/mysql.gpg
sudo apt update
apt-cache policy mysql-server

After source cleanup, the policy output should no longer list repo.mysql.com. On Ubuntu 24.04 or 22.04, the candidate usually returns to Ubuntu’s MySQL 8.0 package unless another MySQL source is configured.

Package removal does not necessarily delete databases. Delete the data paths only after confirming your backup and accepting permanent data loss.

This cleanup permanently deletes MySQL databases, logs, and configuration. Do not run it on a server with data you need to keep, or while MariaDB or another MySQL-compatible server still uses these paths.

sudo rm -rf /var/lib/mysql /var/log/mysql /etc/mysql

Troubleshoot MySQL 8.4 on Ubuntu

Fix NO_PUBKEY B7B3B788A8D3785C During apt update

If sudo apt update reports NO_PUBKEY B7B3B788A8D3785C, re-import the current MySQL signing key and refresh APT.

curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xb7b3b788a8d3785c" | gpg --dearmor | sudo tee /usr/share/keyrings/mysql.gpg > /dev/null
sudo apt update

If the error continues, verify that the source file uses Signed-By: /usr/share/keyrings/mysql.gpg and that the fingerprint matches the key identity shown earlier.

Fix Package Not Found or Wrong MySQL Version

If APT cannot find mysql-server from MySQL 8.4, inspect the repository file and candidate version.

cat /etc/apt/sources.list.d/mysql.sources
apt-cache policy mysql-server

Ubuntu 24.04 should use Suites: noble, and Ubuntu 22.04 should use Suites: jammy. The Components line must be mysql-8.4-lts. If the candidate still shows MySQL 8.0, run sudo apt update again and re-check for repository or key errors.

Handle MariaDB or Other MySQL Fork Conflicts

MySQL packages conflict with MariaDB server packages. Before installing MySQL on a host that may already run MariaDB, check the installed packages and simulate the change.

dpkg -l 'mariadb*' | grep '^ii' || echo 'No installed MariaDB packages found.'
apt-get -s install mysql-server

If the simulation lists MariaDB removals, dependency conflicts, or held packages, stop and plan a database migration. Export databases, test restores, and confirm application compatibility before replacing server packages.

Fix Access Denied for root

On Ubuntu’s default packages, mysql -u root -p can fail because root uses socket authentication. Use sudo mysql for local administration.

sudo mysql

If you intentionally need password-based root login, switch the root account to caching_sha2_password from inside the MySQL shell.

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_strong_password';
FLUSH PRIVILEGES;
EXIT;

Use a strong password and store it in your normal secrets workflow. Avoid mysql_native_password unless a legacy application absolutely requires it and you have verified that your MySQL 8.4 build still loads the plugin.

Diagnose a MySQL Service That Will Not Start

Check the service state, recent journal entries, the MySQL error log, and port 3306 listeners before changing configuration files.

sudo systemctl status mysql --no-pager
sudo journalctl -u mysql -n 80 --no-pager
sudo tail -n 80 /var/log/mysql/error.log
sudo ss -ltnp | grep ':3306' || echo 'No MySQL listener found on port 3306.'

If another service already owns port 3306/tcp, stop the conflicting service or change one service to a different port. Avoid broad ownership resets on /var/lib/mysql unless the logs specifically show a permissions problem, because database directory permissions should not be changed casually.

Use Noninteractive Installation Only for Automation

Interactive installation is safer for normal server setup because you can enter the root password directly. For disposable automation or configuration-management workflows, preseed the MySQL Community prompts before installing.

sudo debconf-set-selections <<'EOF'
mysql-community-server mysql-community-server/root-pass password your_strong_password
mysql-community-server mysql-community-server/re-root-pass password your_strong_password
EOF
sudo DEBIAN_FRONTEND=noninteractive apt install -y mysql-server

Replace your_strong_password before running the command. Do not leave production passwords in shell history, shared terminal logs, or repository-managed scripts.

Fix mysql or mysql_secure_installation Command Not Found

If the server is installed but the classic client command is missing, install the client package from the same source as your server.

sudo apt install mysql-client
mysql --version

If mysql_secure_installation is missing, verify that the server package is installed from the intended source, then reinstall mysql-server after your Ubuntu or Oracle repository path is correct.

dpkg -l 'mysql-server*' 'mysql-community-server*' | grep '^ii'
sudo apt install mysql-server

Conclusion

MySQL 8.4 on Ubuntu uses two different paths: Ubuntu 26.04 installs the 8.4 branch from default APT sources, while Ubuntu 24.04 and 22.04 need Oracle’s repository locked to mysql-8.4-lts. After installation, verify the service, run mysql_secure_installation, and use the authentication method that matches your package source. For upgrades from MySQL 8.0 or migrations away from MariaDB, back up first and treat the package change as a planned database maintenance window.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: