Resolving GPG Signature Failures During MySQL Community Server Installation
When attempting to install mysql-community-server on a RHEL-based system using yum, you may encounter an error indicating that the installed GPG keys do not match those required for the specific package version. The error message explicitly states: "The GPG keys listed for the 'MySQL 5.7 Community Server' repository are already installed but they are not correct for this package." This usually manifests with a NOKEY warning followed by a failure to verify the signature of packages like mysql-community-libs-compat-5.7.37-1.el7.x86_64.
At its core, this issue stems from a mismatch between the repository metadata and the actual content available in the cache. The package manager (yum or dnf) trusts only packages signed with keys listed in the repo configuration file (typically pointing to /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql). However, if that key is outdated, revoked, or simply different from what the package repository expects for the current version, verification fails.
The error output reveals a critical detail: Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql. This indicates that the system attempted to import a local key but determined it was insufficient or incorrect for the specific repository definition being used. Often, this happens when an old repository definition is cached locally while the upstream GPG keys have rotated or updated.
To resolve this, you must ensure that the correct public key exists in your system's trusted GPG directory and that the repository configuration points to the active key URL. The standard procedure involves refreshing the repository metadata and verifying the keyring.
First, attempt to refresh the local cache of repository data without installing anything. Run the following command:
sudo yum makecache
This forces yum to re-fetch the repo metadata from the configured sources, which often includes updating the list of valid GPG keys if the upstream repository has changed its signing strategy. If the error persists after this step, you need to manually inspect and update the key files.
You can verify which keys are currently installed by running:
rpm -qa gpg-pubkey
If no keys related to MySQL appear, or if they seem stale, download the latest public key directly from the official MySQL repositories. The canonical location for these keys is typically hosted on yumrepo.mysql.com. You can update your system's trusted keyring by downloading the correct key and placing it in /etc/pki/rpm-gpg/:
sudo curl https://repo.mysql.com/RPM-GPG-KEY-mysql-8 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Note that depending on your specific MySQL version (e.g., 5.7 vs 8.0), the key file name might differ slightly, but for most modern community server setups, the -mysql suffix is standard. After updating the key file, you must explicitly import it into the RPM database:
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Once the key is imported, retry the installation command:
sudo yum install mysql-community-server
If you are using dnf instead of yum, the process is identical since dnf is a successor to yum with enhanced dependency resolution. The error logic remains the same: the package signature must be verifiable against a trusted key in the system's keyring.
A potential pitfall in this scenario is modifying repository definitions directly without clearing old metadata. If you have previously configured a custom mirror or used an older repository definition that pointed to a deprecated key, simply replacing the key file might not suffice. In such cases, deleting the /var/cache/yum directory contents before running makecache ensures a clean slate.
Additionally, ensure that your system's clock is synchronized. GPG signatures are timestamped; if your system time is significantly off (especially in the past), verification can fail even with the correct keys installed. Check your time accuracy using:
date
timedatectl status
By aligning your repository metadata, importing the current valid key, and ensuring system time integrity, you eliminate the signature mismatch that triggers the NOKEY error. This approach restores trust in the package manager's verification chain, allowing the installation of mysql-community-server to proceed without interruption.
