How to Install MySQL 8.2 on Ubuntu 22.04 or 20.04

Released on October 25, 2023, MySQL 8.2 marks a significant update to the renowned database management system. This guide will focus on how to install MySQL 8.2 on Ubuntu 22.04 or 20.04 while highlighting the key features of this version. These features are designed to enhance the system’s functionality and user experience:

  • Audit Log Improvements: Simplification of MySQL Enterprise Audit removal.
  • Authentication Changes: Optional use of the mysql_native_password plugin.
  • C API Enhancements: Advanced binding options in prepared statements.
  • Compilation Updates: Compatibility with MSVC 2022 version v17.7.2.
  • Deprecation and Removals: Removal of specific SQL functions.
  • Firewall Features: Dynamic reloading of MySQL Enterprise Firewall’s memory cache.
  • Parallel Event Execution: Improved multi-threading in START REPLICA.
  • Optimizer Enhancements: Efficient set operations through hash table optimization.
  • Performance Schema Additions: New Server Telemetry Metrics service.
  • SQL Syntax Updates: Revised terminology in MySQL Replication.
  • Functionality Changes: Updated libfido2 and OpenSSL library versions.

These advancements in MySQL 8.2 are poised to streamline operations and enrich the database management experience. The following sections will delve into the installation steps on Ubuntu, ensuring you can leverage these new features effectively.

Install MySQL 8.2 on Ubuntu 22.04 or 20.04 via APT

Step 1: Update Ubuntu Packages Before MySQL 8.2 Installation

Initiate the installation process by ensuring your Ubuntu system is up-to-date. This essential step updates all existing software packages, reducing the risk of compatibility issues during the MySQL 8.2 installation. Use these commands:

sudo apt update
sudo apt upgrade

Step 2: Install Essential Packages

Prepare your system for MySQL 8.2 installation by installing the necessary packages. These include tools for secure communication and package management. Verify their presence with:

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl lsb-release -y

Step 3: Import MySQL 8.2 Repositories

Secure your MySQL installation by importing the official GPG key. This ensures the authenticity of the packages you’ll download:

curl -fsSL http://repo.mysql.com/RPM-GPG-KEY-mysql-2023 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mysql.gpg > /dev/null

Add the MySQL 8.2 repository to your system’s software sources. This step enables Ubuntu to fetch MySQL packages from the correct location:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/ubuntu $(lsb_release -cs) mysql-innovation" | sudo tee -a /etc/apt/sources.list.d/mysql.list

For additional tools or MySQL source repository, use the following command:

echo "deb-src [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/ubuntu $(lsb_release -cs) mysql-innovation" | sudo tee -a /etc/apt/sources.list.d/mysql.list

If MySQL Cluster is required, run the additional command:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/ubuntu $(lsb_release -cs) mysql-cluster-innovation" | sudo tee -a /etc/apt/sources.list.d/mysql.list

Step 4: Install MySQL 8.2 on Ubuntu

Update your system’s package list to include the newly added MySQL repository:

sudo apt update

Proceed to install MySQL 8.2 Community Edition Server. This command installs the latest MySQL server along with its dependencies:

sudo apt install mysql-community-server

During installation, you’ll be prompted to create a password for the MySQL root user. This is a crucial step for securing your database:

Setting MySQL 8.2 Root Password on Ubuntu
Setting Up Root Password for MySQL 8.2 on Ubuntu

Choose the default authentication plugin. For most users, selecting the “Use Strong Password Encryption” option is recommended:

Choosing Strong Password Encryption for MySQL 8.2 on Ubuntu
Opting for Strong Password Encryption During MySQL Installation

Finally, verify the successful installation of MySQL 8.2 by checking its installed version:

apt policy mysql-community-server

or

mysql --version
MySQL 8.2 Version Confirmation on Ubuntu
Terminal Command to Check MySQL 8.2 Version

Lastly, verify the service is active, which by default, should be automatically enabled during the installation:

systemctl status mysql
MySQL 8.2 Service Status on Ubuntu Terminal
MySQL Service Status Post-Installation on Ubuntu

If, by some chance the service is not active, run the following command:

sudo systemctl enable mysql --now

Secure MySQL 8.2 on Ubuntu 22.04 or 20.04

Securing your MySQL installation is essential to protect your database from unauthorized access and potential security threats. MySQL 8.2 includes a built-in script, mysql_secure_installation, which streamlines the process of securing your database.

Running the MySQL Security Script on Ubuntu

Execute the mysql_secure_installation script to begin enhancing your MySQL security:

sudo mysql_secure_installation

Interacting with the Security Script on Ubuntu

The script prompts for the root password set during MySQL installation. Follow these steps to strengthen your MySQL security:

  1. Password Settings for Root Accounts
    • You can reset the root password if needed. If you’re confident in the strength of your existing password, you may skip this.
    • To reset, enter the new password twice for confirmation.
  2. Removal of Anonymous Users
    • MySQL installs with an anonymous user, posing a security risk. Remove this user by confirming when prompted.
  3. Disallowing Root Login Remotely
    • Limit root user access to local connections only. This step prevents remote login attempts to the root user, a key security measure.
  4. Removal of Test Database
    • MySQL includes a ‘test’ database accessible to all. Remove this database to prevent unauthorized access in production environments.
  5. Reloading Privilege Tables
    • Apply your changes by reloading the privilege tables.

Each of these steps contributes to a more secure MySQL environment, significantly reducing the risk of vulnerabilities and unauthorized access.

Upgrade Existing Databases with MySQL 8.2 on Ubuntu 22.04 or 20.04

When you upgrade from MySQL 8.0 to MySQL 8.2, it’s crucial to update your existing databases to ensure compatibility with the new version. This process involves running the mysql_upgrade command, which checks and updates all the tables as needed.

After completing the MySQL 8.2 installation over an existing 8.0 setup, open your Ubuntu terminal and execute the following command:

sudo mysql_upgrade

This command performs several functions:

  • It checks all tables in all databases for compatibility with the current version of MySQL.
  • It upgrades the system tables to be compatible with the new version.
  • It performs a check to ensure that all tables are correctly structured.

Once mysql_upgrade completes, restart the MySQL server to apply the changes:

sudo systemctl restart mysql

Running mysql_upgrade is a best practice after any major version upgrade of MySQL, ensuring that all your databases and tables are fully compatible with the new version’s features and improvements.

Managing MySQL 8.2 on Ubuntu 22.04 or 20.04

Maintaining your MySQL server on Ubuntu involves essential tasks like updates, upgrades, and uninstallation when necessary. Utilizing Ubuntu’s command-line tools facilitates keeping your MySQL server up-to-date and secure.

Update MySQL 8.2 on Ubuntu

Regularly updating your MySQL server is crucial for smooth operation. Updates often include bug fixes, security enhancements, and new features. After adding the official MySQL 8.2 CE APT repository, update MySQL with:

sudo apt update && sudo apt upgrade

This command combines updating the package list and upgrading all out-of-date packages, ensuring your MySQL server is current.

Remove MySQL 8.2 from Ubuntu

If MySQL is no longer needed, its removal from your system includes stopping the service and uninstalling the software.

Stop the MySQL Service on Ubuntu

Ensure MySQL is not running before uninstallation:

sudo systemctl stop mysql --now

Remove MySQL and Its Dependencies from Ubuntu

Remove MySQL server and related packages with:

sudo apt remove mysql-community-server

This step clears MySQL and its dependencies, freeing up system resources.

Remove MySQL 8.2 Repository

To prevent future updates from the MySQL repository:

sudo rm /etc/apt/sources.list.d/mysql.list

Removing the repository file stops your system from checking for MySQL updates, streamlining your APT sources.

Conclusion

In this guide, we walked through the essential steps to successfully install MySQL 8.2 on Ubuntu 22.04 or 20.04. From initial setup to securing your database and managing configurations, each step was designed to ensure a smooth and secure MySQL experience. As you embark on using MySQL 8.2, remember to regularly update and maintain your database for optimal performance and security. Embrace the new features and improvements that MySQL 8.2 offers, and don’t hesitate to explore its full potential to enhance your data management capabilities on Ubuntu.

Leave a Comment