# MySQL Upgrade from 8.0.4 to 8.4.x  (Ubuntu)

This article provides step-by-step instructions to upgrade MySQL from **version 8.0.4 to 8.4**.**x.** It covers prerequisites, pre-upgrade checks, installation steps, post-upgrade validations, and rollback procedures to ensure a safe and production-ready upgrade.

### Prerequisites

* **OS Compatibility**
  * Confirm the operating system supports MySQL 8.4.
  * **Recommended:** Ubuntu 22.04 LTS or later.
  * Check OS version:

    ```bash
    cat /etc/os-release
    ```
* **System Requirements**
  * **Disk space:** Sufficient for backups and rollback
  * **Memory:** Minimum 16 GB RAM
  * **Access:** Root or sudo privileges

### Pre-Upgrade Checks

* **Backup**
  * **Logical backup:**

    ```bash
    mysqldump -u root -p ovaledgedb > /home/ubuntu/mysql_backup/ovaledgedb_backup.sql
    ```

    Ensure you use the correct schema.

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/TcNdhFdItvAF1e1anKSv/image.png" alt=""><figcaption></figcaption></figure>
  * Physical backup (recommended):
    * Use Percona XtraBackup or filesystem-level copy.
  * **Backup configuration files:**

    ```bash
    sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /home/ubuntu/mysql_backup/
    sudo cp -a /var/lib/mysql /home/ubuntu/mysql_backup/
    ```

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/txFaB5O1btBkRqD2nbjg/image.png" alt=""><figcaption></figcaption></figure>
* **Collect Pre-Upgrade Database Information**
  * **Database size query:**

    ```sql
    SELECT 
        table_schema AS "Database Name", 
        ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS "DB Size (MB)"
    FROM information_schema.tables 
    GROUP BY table_schema;
    ```

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/X5fVSKlzQ6GaiD7HkJdK/image.png" alt=""><figcaption></figcaption></figure>
  * Row count query:\
    \[[Download Query File](https://ovaledge.s3.us-west-1.amazonaws.com/queries/dbsize.sql?utm_source=chatgpt.com)]

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/a8UIZdSB13NWJT5gyzwd/image.png" alt=""><figcaption></figcaption></figure>
  * Save query outputs for post-upgrade validation.

### Upgrade Execution

* **Stop MySQL Service**

  ```bash
  sudo systemctl stop mysql
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/LMl9IuAX1hb7bg7OJVgO/image.png" alt=""><figcaption></figcaption></figure>
* **Download MySQL APT Repository**&#x20;
* Update package manager repo i,e, using deb packages for ubuntu.

  ```bash
  cd
  wget https://dev.mysql.com/get/mysql-apt-config_0.8.33-1_all.deb
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/O8EvpVfNXOwfZ8ySXl5G/image.png" alt=""><figcaption></figcaption></figure>
* **Update Repository**\
  Update the deb packages as shown below.

  ```bash
  sudo dpkg -i mysql-apt-config_0.8.33-1_all.deb
  ```

  * Select the highlighted package below and hit Enter.

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/2kLKwC0rvZgI6vaGBozK/image.png" alt=""><figcaption></figcaption></figure>
  * Select MySQL 8.4 LTS when prompted.

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/iFAlMdO5kFt2EhoXenzf/image.png" alt=""><figcaption></figcaption></figure>
  * Confirm selections and continue.

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/RPqJgdAgouynWiVESY1V/image.png" alt=""><figcaption></figcaption></figure>
  * Finally you will get below screen,

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/Oj2SheWggeztaLZNYLEQ/image.png" alt=""><figcaption></figcaption></figure>
* **Update Packages**\
  Update the apt package repository.

  ```bash
  sudo apt update -y
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/24illUDH2mTZfX9pli6Q/image.png" alt=""><figcaption></figcaption></figure>
* **Upgrade MySQL Server**\
  Run the following command to upgrade the MySQL server:

  ```bash
  sudo apt-get install mysql-server
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/1uCGQGCFlzvPt2PQEwly/image.png" alt=""><figcaption></figcaption></figure>
* **Update Configuration**\
  Open the MySQL configuration file:

  ```bash
  sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
  ```

  Add:

  ```
  mysql_native_password=ON
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/b2VhVi10ctFOQCVryVL7/image.png" alt=""><figcaption></figcaption></figure>

  Save file and restart MySQL

  ```bash
  sudo systemctl restart mysql
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/D9PJ6nLxc2MOUoqyIrU2/image.png" alt=""><figcaption></figcaption></figure>
* **Verify Version**

  ```bash
  mysql --version
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/6627Sfh8HxJpE3MxNmOY/image.png" alt=""><figcaption></figcaption></figure>

### Post-Upgrade Validations

* **Row Count Verification**

  ```bash
  mysql -u root -p
  ```

  Run \[[Row Count Query](https://ovaledge.s3.us-west-1.amazonaws.com/queries/dbsize.sql?utm_source=chatgpt.com)] and compare results with pre-upgrade counts.

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/LM5mc5KRgkIrJgFzdTYv/image.png" alt=""><figcaption></figcaption></figure>
* **Database Size Verification**<br>

  ```sql
  SELECT 
      table_schema AS "Database Name", 
      ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) AS "DB Size (MB)"
  FROM information_schema.tables 
  GROUP BY table_schema;
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/4e4XfvDS34WIO8AFmLaa/image.png" alt=""><figcaption></figcaption></figure>

  Compare with pre-upgrade values.
* **Update MySQL Parameters**\
  Edit `/etc/mysql/mysql.conf.d/mysqld.cnf` and add:

  ```
  max_binlog_size=1GB
  binlog_expire_logs_seconds=2592000
  group_concat_max_len=50000
  max_connections=600
  innodb_buffer_pool_size=10GB
  max_allowed_packet=1G
  bind-address=0.0.0.0
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/A5dUtKvRQ8rKGliFYeJp/image.png" alt=""><figcaption></figcaption></figure>

  Adjust values based on instance size.\
  **Restart MySQL:**

  ```bash
  sudo systemctl restart mysql
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/NyLQWRQu3km9TYXZMIKO/image.png" alt=""><figcaption></figcaption></figure>
* **Update OvalEdge User Password**

  ```sql
  ALTER USER 'ovaledge'@'localhost' IDENTIFIED BY '<Password>';
  ALTER USER 'ovaledge'@'%' IDENTIFIED BY '<Password>';
  FLUSH PRIVILEGES;
  ```
* **Check Logs**

  ```bash
  tail -n 100 /var/log/mysql/error.log
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/IHLLdrIa1BweZWLhsfbm/image.png" alt=""><figcaption></figcaption></figure>
* Once validations are complete, point the OvalEdge application to MySQL 8.4.

### Rollback Plan (If Needed)

* Back up MySQL configuration and data directory:

  ```bash
  sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /home/ubuntu/mysql8.4_backup/
  sudo cp -a /var/lib/mysql /home/ubuntu/mysql8.4_backup/
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/oFi7D7e6vQYpXIDErs31/image.png" alt=""><figcaption></figcaption></figure>
* Stop MySQL service.
* Reinstall MySQL 8.0.4.
* Restore data from backups.

### Additional Information

* Test MySQL 8.4 installation in a separate folder before applying in production.
* Example: MySQL 8.4.4 installation in a separate folder on Ubuntu.

***

Copyright © 2025, OvalEdge LLC, Peachtree Corners, GA, USA.
