# MySQL Upgrade from 8.0.4 to 8.4.x (RHEL) Internet

This article describes the steps, checks, and dependencies required to upgrade MySQL from version 8.0.4 to 8.4.x on RHEL 8 systems. It covers prerequisites, pre-upgrade tasks, upgrade execution, post-upgrade validations, and rollback procedures to ensure a safe and reliable production upgrade.

### Prerequisites

#### **OS Compatibility**

* Verify that the operating system supports MySQL 8.4.
* Recommended: RHEL 8.x or later.
* Check the OS version:

  ```bash
  cat /etc/os-release
  ```

#### **System Requirements**

* Ensure sufficient disk space for backup and rollback (`df -Th`).
* Confirm root or sudo access.
* All listed commands must be executed.

## Pre-Upgrade Checks

### **Backup**

* Perform a logical backup of the MySQL database.
* **Log Management Procedure**
* Confirm you are backing up the correct schema.

  ```bash
  mkdir /home/ec2-user/mysql_backup  
  mysqldump -u root -p ovaledgedb > /home/ec2-user/mysql_backup/ovaledgedb_backup.sql
  ```

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

{% hint style="info" %}
Ensure sufficient space is available before running the `mysqldump` command.
{% endhint %}

* **Back up configuration files:**

  ```bash
  sudo cp /etc/my.cnf /home/ec2-user/mysql_backup/  
  sudo cp -a /var/lib/mysql /home/ec2-user/mysql_backup/
  ```

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

**Database Size and Row Count Check**

* Run the following queries before upgrading:

  **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/F7wCaQGx17BSrwptpiTv/image.png" alt=""><figcaption></figcaption></figure>

  **Row count query:**\
  \&#xNAN;*(*[*Download SQL script*](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/kQmDQf0y67Ey3TqXvRxm/image.png" alt=""><figcaption></figcaption></figure>
* Save outputs for post-upgrade comparison.

## Upgrade Execution

### **Stop MySQL Services**

Stop MySQL services by running the following command

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

```bash
mysql --version  
sudo systemctl stop mysqld
```

### **Install MySQL 8.4.x**

* **Download repository package:**

  ```bash
  wget https://dev.mysql.com/get/mysql84-community-release-el8-1.noarch.rpm
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/5xYdazB1L4gMUsaPYxMX/image.png" alt=""><figcaption></figcaption></figure>
* **Install repository:**

  ```bash
  sudo yum localinstall mysql84-community-release-el8-1.noarch.rpm
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/fr8ZX1m6SHIWyjm35jWu/image.png" alt=""><figcaption></figcaption></figure>
* Disable any existing MySQL 8.0 repositories:

  ```bash
  sudo vi /etc/yum.repos.d/mysql-community.repo
  # enable=0 (disable) / enable=1 (enabled)
  ```
* Disable MySQL module in the package manager:

  ```bash
  sudo yum module disable mysql -y
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/2kHgw0kwOu5RorJSvfEz/image.png" alt=""><figcaption></figcaption></figure>
* Install MySQL 8.4.x:

  ```bash
  sudo yum install mysql-community-server
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/FbFzB7pOdDEG9bJ2V1gJ/image.png" alt=""><figcaption></figcaption></figure>
* Check installed version:

  ```bash
  mysql --version
  ```

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

**Update Configuration**

* Edit the configuration file:

  ```bash
  sudo vi /etc/my.cnf
  mysql_native_password=ON
  ```
* Save file and restart MySQL:

  ```bash
  sudo systemctl restart mysqld  
  sudo systemctl status mysqld
  ```

  <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/Ao0bnVDlkS6NMP8j9z8q/image.png" alt=""><figcaption></figcaption></figure>
* Verify upgrade by checking MySQL version.

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

## Post-Upgrade Validations

### **Verify Row Counts and Database Size**

* Connect to MySQL:

  ```bash
  mysql -u root -p
  ```
* Run validation queries:
  * Row count query: [SQL Script](https://ovaledge.s3.us-west-1.amazonaws.com/queries/dbsize.sql)<br>

    <figure><img src="https://content.gitbook.com/content/ztcvwwOJCeaE1n6oHp4C/blobs/fkyhfugiQNixTXrZqw7a/image.png" alt=""><figcaption></figcaption></figure>
  * 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/Ttml9V3gSsc3az178aZl/image.png" alt=""><figcaption></figcaption></figure>
* Compare results with pre-upgrade outputs.

**Update MySQL Parameters**

* Add/update parameters in `/etc/my.cnf`:

  ```
  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
  ```
* Adjust values as per client instance size.<br>

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

  ```bash
  sudo systemctl restart mysqld
  ```

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

### **Update Application User Passwords (Optional)**

* Change OvalEdge MySQL user passwords:

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

At this stage, the MySQL database has been upgraded to version 8.4 and the default OvalEdge MySQL password has been changed.

### Rollback Plan (if required)

* Take backup of MySQL 8.4 installation before rollback:

  ```bash
  mkdir /home/ec2-user/mysql8.4_backup  
  sudo cp /etc/my.cnf /home/ec2-user/mysql8.4_backup  
  sudo cp -a /var/lib/mysql /home/ec2-user/mysql8.4_backup
  ```
* Stop MySQL services, reinstall MySQL 8.0.4, start the service, and restore data from backups.

***

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