MySQL 8.4 LTS is the current long-term support release of the widely used relational database management system, offering extended support through 2032, improved InnoDB performance, and enhanced security defaults including stronger password policies. Common use cases include powering web applications like WordPress and Laravel, storing user data for custom applications, managing e-commerce inventory and transactions, and serving as the backend for CMS platforms that rely on PHP scripting.
This guide demonstrates how to install MySQL 8.4 on Ubuntu using the terminal. Ubuntu 26.04 includes MySQL 8.4 in its default repositories, while Ubuntu 24.04 and 22.04 require MySQL’s official APT repository. Both paths are covered below so you can choose the method that matches your Ubuntu release.
Refresh Ubuntu Packages Before MySQL 8.4 Installation
Updating your system before starting the installation ensures all existing packages are current, minimizing the chance of conflicts during MySQL 8.4 installation.
Run the following commands to update and upgrade your system:
sudo apt update
sudo apt upgrade
Default MySQL Versions by Ubuntu Release
MySQL versions differ across Ubuntu LTS releases. The following table shows what each release provides by default and what options are available through MySQL’s official repository.
| Ubuntu Release | Default MySQL | Official Repo Available | Best For |
|---|---|---|---|
| Ubuntu 26.04 LTS | MySQL 8.4.x | Not yet available | New deployments using default packages |
| Ubuntu 24.04 LTS | MySQL 8.0.x | MySQL 8.4 LTS | Production servers needing LTS support through 2032 |
| Ubuntu 22.04 LTS | MySQL 8.0.x | MySQL 8.4 LTS | Existing deployments requiring extended MySQL support |
These steps cover Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Ubuntu 26.04 users can install MySQL 8.4 directly from default repositories (Option 1). Ubuntu 24.04 and 22.04 users must use MySQL’s official APT repository (Option 2) because their default repositories only provide MySQL 8.0. MySQL has not yet released packages for Ubuntu 26.04 (resolute) in their official repository.
If you only need MySQL 8.0, Ubuntu 24.04 and 22.04 include it in default repositories. See our MySQL 8.0 installation guide for simpler setup without adding external repositories.
Choose Your MySQL 8.4 Installation Method
MySQL 8.4 installation on Ubuntu offers two primary paths depending on your Ubuntu release. Select the method that matches your system.
| Installation Method | Version Source | Ubuntu Releases | Updates | Best For |
|---|---|---|---|---|
| Ubuntu Repository | Ubuntu’s curated packages | Ubuntu 26.04 only | Via apt upgrade | Stability-focused environments, seamless system integration |
| MySQL Official Repository | MySQL Community Server | Ubuntu 24.04, 22.04 | Via apt upgrade | Systems needing MySQL 8.4 on older Ubuntu releases |
Option 1: Install MySQL 8.4 from Ubuntu Repository (Ubuntu 26.04 Only)
Ubuntu 26.04 includes MySQL 8.4 in its default repositories. This method provides a stable, thoroughly tested version integrated with Ubuntu’s ecosystem. Ubuntu’s package maintainers verify each release against the rest of the system, making this the safest choice for production servers where uptime matters more than accessing upstream releases immediately.
To install MySQL with this method, execute the following command:
sudo apt install mysql-server
The installation is non-interactive. MySQL installs, the service starts automatically, and Ubuntu defaults to the auth_socket plugin for the root user instead of prompting for a password. After installation, run the security script in the “Secure MySQL 8.4” section to set a root password and tighten defaults.
To verify the installation, check the MySQL version:
mysql --version
Example output:
mysql Ver 8.4.7 for Linux on x86_64 (Ubuntu)
Option 2: Install MySQL 8.4 from Official Repository (Ubuntu 24.04/22.04)
Ubuntu 24.04 and 22.04 provide MySQL 8.0 in their default repositories. To install MySQL 8.4 LTS on these releases, use MySQL’s official APT repository. MySQL 8.4 LTS receives bug and security fixes through 2032, offering the longest support runway for production deployments.
Install Repository Prerequisites
Install the required packages before proceeding:
sudo apt install gpg ca-certificates software-properties-common curl lsb-release -y
Add the MySQL APT Repository
To install MySQL 8.4 from its official repository, import the signing key and add the repository to your system.
Import the MySQL signing key from Ubuntu’s keyserver. This key (B7B3B788A8D3785C) verifies packages from the MySQL APT repository (see the curl command guide for details on the flags used):
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xb7b3b788a8d3785c" | sudo gpg --dearmor -o /usr/share/keyrings/mysql.gpg
Create a DEB822 source file for MySQL 8.4 LTS and the tools component:
cat <<EOF | sudo tee /etc/apt/sources.list.d/mysql.sources
Enabled: yes
Types: deb deb-src
URIs: https://repo.mysql.com/apt/ubuntu
Suites: $(lsb_release -cs)
Components: mysql-8.4-lts mysql-tools
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/mysql.gpg
EOF
Verify the file contents:
cat /etc/apt/sources.list.d/mysql.sources
Expected output:
Enabled: yes Types: deb deb-src URIs: https://repo.mysql.com/apt/ubuntu Suites: noble Components: mysql-8.4-lts mysql-tools Architectures: amd64 Signed-By: /usr/share/keyrings/mysql.gpg
The Architectures field matches your system architecture (amd64 or arm64), and Suites reflects your Ubuntu codename (jammy or noble). The mysql.gpg reference points to the key you imported. If you see nothing, the repository file is empty and needs to be re-created; see the Troubleshooting section.
Refresh APT After Adding MySQL
Refresh the APT cache to recognize the newly added repository:
sudo apt update
Install MySQL 8.4 Community Edition Server
With the repository configured, install MySQL 8.4 Community Edition Server:
sudo apt install mysql-community-server
During installation, you’ll see two interactive prompts. First, set a root password:
┌─────────────────────┤ Configuring mysql-community-server ├─────────────────────┐ │ Please provide a strong password that will be set for the root account of │ │ your MySQL installation. │ │ │ │ Enter root password: ******** │ │ │ │ <Ok> │ └────────────────────────────────────────────────────────────────────────────────┘
After confirming the password, select the authentication plugin:
┌─────────────────────┤ Configuring mysql-community-server ├─────────────────────┐ │ Select the default authentication plugin: │ │ │ │ (*) Use Strong Password Encryption (RECOMMENDED) │ │ ( ) Use Legacy Authentication Method (Retain MySQL 5.x Compatibility) │ │ │ │ <Ok> │ └────────────────────────────────────────────────────────────────────────────────┘
Choose Use Strong Password Encryption unless you have legacy applications that require MySQL 5.x-compatible authentication. The strong encryption option uses caching_sha2_password, which is more secure and recommended for all new installations.
To confirm the installation, check the installed MySQL version:
apt policy mysql-community-server
Example output:
mysql-community-server:
Installed: 8.4.8-1ubuntu24.04
Candidate: 8.4.8-1ubuntu24.04
Version table:
*** 8.4.8-1ubuntu24.04 500
500 https://repo.mysql.com/apt/ubuntu noble/mysql-8.4-lts amd64 Packages
100 /var/lib/dpkg/status
This confirms MySQL 8.4 is installed. The version number shows your installed MySQL build, and the repository information confirms the package came from the official MySQL source.
After installation, consider setting up phpMyAdmin for web-based database management, and configure your UFW firewall to restrict database access to trusted hosts only.
Service Commands for MySQL 8.4
MySQL 8.4 automatically activates after installation and sets itself to auto-start on system boot. The following table provides a quick reference for common service management tasks:
| Task | Command |
|---|---|
| Check service status | systemctl status mysql |
| Start MySQL | sudo systemctl start mysql |
| Stop MySQL | sudo systemctl stop mysql |
| Restart MySQL | sudo systemctl restart mysql |
| Enable auto-start on boot | sudo systemctl enable mysql |
| Disable auto-start on boot | sudo systemctl disable mysql |
Verify MySQL Service Status
Check the current status of your MySQL service:
systemctl status mysql
Successful output example:
mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
Active: active (running) since Mon 2026-01-27 10:45:32 UTC; 2min 15s ago
Main PID: 1234 (mysqld)
Tasks: 28 (limit: 9405)
Memory: 265.4M
CPU: 1.234s
CGroup: /system.slice/mysql.service
└─1234 /usr/sbin/mysqld
Look for the line that says Active: active (running) to confirm MySQL is running properly. The “enabled” status means it will auto-start when you reboot. If you see inactive (dead), the service is stopped; use sudo systemctl start mysql to start it.
Verify MySQL Connection After Installation
After installation completes, verify that MySQL is accepting connections. For Ubuntu’s repository packages (26.04), root uses the auth_socket plugin, so connect with:
sudo mysql
If you installed from the MySQL Community repository and set a root password, connect with:
mysql -u root -p
Upon successful authentication, you’ll see the MySQL prompt:
mysql>
This confirms MySQL is running and accepting connections. Type EXIT; to close the connection and return to the terminal.
Understanding auth_socket vs Password Authentication
MySQL on Ubuntu supports two primary authentication methods for the root user. The method you use depends on how you installed MySQL:
| Authentication | How It Works | Login Command | Best For |
|---|---|---|---|
auth_socket | Verifies the Linux user running the command matches the MySQL user. No password needed when using sudo | sudo mysql | Local server access, automated scripts running as root |
Password (caching_sha2_password) | Traditional password authentication. Required for remote connections and web applications | mysql -u root -p | Web apps (WordPress, phpMyAdmin), remote access, shared servers |
Ubuntu’s default packages (26.04) use auth_socket by default. MySQL’s official repository prompts you to set a password during installation. If you need password-based authentication on an auth_socket installation (for example, to allow WordPress to connect), switch the authentication method in the Troubleshooting section below.
Secure MySQL 8.4 on Ubuntu
Upon installing MySQL, certain default settings may not meet production security standards. MySQL provides the mysql_secure_installation script to remove unsafe defaults and enforce security best practices.
Running the MySQL Security Script
The mysql_secure_installation script enhances security by removing anonymous users, disabling remote root login, and deleting the test database. If you installed from Ubuntu’s repository and root uses the auth_socket plugin, the script may skip the root password prompt; it asks for a password only if your installation already set one (such as the MySQL Community path).
sudo mysql_secure_installation
Interacting with the Security Script
The script walks you through five security hardening steps. Accepting all recommendations (answering “Y” to each prompt) follows security best practices for both development and production systems:
1. Password Settings for Root Accounts
New password: <---- SET NEW PASSWORD Re-enter new password: <---- RE-ENTER NEW PASSWORD
You can set or reset the root password here. If you already set one during installation (MySQL Community path), you may skip this step or change it now.
2. Removal of Anonymous Users
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press ENTER
MySQL includes anonymous user accounts by default that allow unauthenticated connections. Removing them prevents anyone from connecting without valid credentials.
3. Disallowing Root Login Remotely
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press ENTER
This restricts root connections to localhost only, preventing remote brute-force attacks against the administrative account.
4. Removal of Test Database
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press ENTER
The default test database is accessible to anyone without authentication. Delete it before deploying to production.
5. Reloading Privilege Tables
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y <---- Type Y then press ENTER
This applies all the security changes immediately without requiring a MySQL restart.
Managing MySQL 8.4
Managing your MySQL server involves routine tasks such as updates and, when necessary, uninstallation. Ubuntu provides efficient command-line utilities for these tasks.
Update MySQL 8.4
Regular updates maintain security and stability. Whether you installed from Ubuntu’s repository or the MySQL APT repository, updating MySQL follows the normal APT workflow:
sudo apt update && sudo apt upgrade
The apt update command retrieves available package updates, while apt upgrade installs them to your system, including any available MySQL updates.
Remove MySQL 8.4
If you no longer require MySQL on your Ubuntu system, follow these steps to cleanly remove the software. Before proceeding, back up any databases you want to keep.
Back Up Databases Before Removal
Export all databases to a SQL file before uninstalling MySQL. This creates a backup you can restore later if needed:
sudo mysqldump --all-databases > ~/mysql-backup-$(date +%F).sql
If you use password authentication, add -u root -p to the command. Store this backup file securely before proceeding with removal.
Stop the MySQL Service
Stop MySQL before uninstalling:
sudo systemctl stop mysql
Remove MySQL and Its Dependencies
Remove the MySQL server and its dependencies. Use autoremove to remove packages, or purge to also delete configuration files:
MySQL Community repository installation:
sudo apt autoremove --purge mysql-community-server
Ubuntu default repository installation:
sudo apt autoremove --purge mysql-server
The --purge flag removes both the packages and their configuration files. Omit --purge if you plan to reinstall MySQL later and want to preserve your configuration.
Remove MySQL 8.4 Repository
If you no longer intend to use MySQL and had previously imported the MySQL 8.4 Community Repository, remove the repository from your system:
sudo rm /etc/apt/sources.list.d/mysql.sources
sudo rm /usr/share/keyrings/mysql.gpg
sudo apt update
This step ensures your system won’t attempt to check the MySQL repository during system-wide upgrades, keeping your APT sources streamlined.
Remove MySQL Data Files (Optional)
The package removal does not delete your databases. To completely remove all MySQL data, including databases, user accounts, and logs:
This permanently deletes all MySQL databases. Ensure you have a backup (see above) before running these commands.
sudo rm -rf /var/lib/mysql
sudo rm -rf /var/log/mysql
sudo rm -rf /etc/mysql
Troubleshooting MySQL 8.4 Installation
Installation and configuration issues can occur due to system configuration, conflicting packages, or permission problems. This section covers common errors and practical solutions.
MySQL Service Won’t Start After Installation
Symptom: systemctl status mysql shows inactive (dead) or displays error messages.
Solution: Check the MySQL error log to understand why the service failed:
sudo tail -50 /var/log/mysql/error.log
Port 3306 already in use: Another MySQL instance or service is using the default port:
sudo lsof -i :3306
If another process uses the port, either stop that process or configure MySQL to use a different port in /etc/mysql/mysql.conf.d/mysqld.cnf (change port = 3306 to port = 3307).
Permission denied on data directory: The MySQL user lacks write permissions:
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 750 /var/lib/mysql
After fixing permissions, attempt to start MySQL again:
sudo systemctl start mysql
Access Denied for User ‘root’ at Login
Symptom: mysql -u root -p returns “Access denied for user ‘root’@’localhost'”
Solution: Check whether root uses socket authentication. On Ubuntu’s repository packages, root uses the auth_socket plugin, so connect with sudo mysql instead of a password. If you prefer a password, run the following SQL inside that session:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_new_password';
FLUSH PRIVILEGES;
For installations that already rely on a root password (such as the MySQL Community repository), reset it by starting MySQL in safe mode:
sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables &
mysql -u root
Once connected, flush privileges and set a new password:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
EXIT;
Stop the safe mode instance and restart MySQL normally:
sudo pkill mysqld
sudo systemctl start mysql
Socket Error: Can’t Connect to Local MySQL Server
Symptom: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Solution: This error indicates the MySQL service is not running or the socket file doesn’t exist. Verify the service is running:
sudo systemctl status mysql
If the service is stopped, start it:
sudo systemctl start mysql
If the error persists after starting, check if the socket file exists:
ls -la /var/run/mysqld/mysqld.sock
If the file doesn’t exist, the data directory may be corrupted. Reinstall MySQL by removing it and reinstalling from scratch.
Repository Not Found During Installation
Symptom: E: Unable to locate package mysql-community-server
Solution: The MySQL repository either wasn’t imported correctly or the APT cache wasn’t refreshed. Verify the repository file exists:
cat /etc/apt/sources.list.d/mysql.sources
If the file is empty or missing, re-import the repository using the commands in “Option 2” above. After re-importing, refresh the APT cache:
sudo apt update
GPG Key Error During apt update
Symptom: GPG error: http://repo.mysql.com/apt/ubuntu ... NO_PUBKEY or EXPKEYSIG B7B3B788A8D3785C
Solution: The MySQL GPG key may be missing, expired, or corrupted. Re-import the current key:
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xb7b3b788a8d3785c" | sudo gpg --dearmor -o /usr/share/keyrings/mysql.gpg
sudo apt update
If the error persists, verify the key was imported:
gpg --with-colons /usr/share/keyrings/mysql.gpg
Installation Hangs or Prompts Unexpectedly
Symptom: sudo apt install mysql-community-server hangs without prompting for password or shows configuration dialogs that won’t respond.
Solution: Pre-set the MySQL root password before installation to avoid interactive prompts:
echo "mysql-community-server mysql-community-server/root-pass password YourPassword123" | sudo debconf-set-selections
echo "mysql-community-server mysql-community-server/re-root-pass password YourPassword123" | sudo debconf-set-selections
sudo DEBIAN_FRONTEND=noninteractive apt install -y mysql-community-server
Replace YourPassword123 with a strong password. The DEBIAN_FRONTEND=noninteractive flag prevents interactive prompts during installation.
MySQL Command Not Found
Symptom: mysql: command not found when attempting to connect.
Solution: The MySQL client may not be installed. Install the mysql-client package:
sudo apt install mysql-client
After installation, verify the client works:
mysql --version
MySQL 8.4 Installation FAQ
No. Ubuntu 24.04 and 22.04 include MySQL 8.0 by default. To install MySQL 8.4 LTS, you must add the official MySQL APT repository. Ubuntu 26.04 includes version 8.4 natively.
Ubuntu’s default MySQL configuration uses auth_socket authentication, which requires sudo mysql instead of a password. If you need password access (for tools like phpMyAdmin or WordPress), you must switch the root user to caching_sha2_password authentication.
Yes. Adding the MySQL 8.4 repository and running sudo apt upgrade will update the existing installation. However, you must back up all databases using mysqldump and stop applications accessing the database before upgrading, as major version upgrades carry risks.
MySQL 8.4 is a Long-Term Support (LTS) release configured for stability and 8 years of support (until 2032). Innovation releases (like 8.1–8.3) are short-lived versions with new features, typically intended for development and testing environments rather than critical production workloads.
Conclusion
MySQL 8.4 LTS provides a stable relational database platform with long-term support through 2032. Ubuntu 26.04 users can install directly from default repositories, while Ubuntu 24.04 and 22.04 users need MySQL’s official APT repository. After installation, run mysql_secure_installation to harden your database, then verify connectivity with the authentication method appropriate for your setup. Your MySQL server is now ready to support web applications, data storage, and production workloads.