Encountering a GPG error while updating your MySQL repository on Ubuntu Focal can halt your ability to securely install or update MySQL packages. This error typically arises due to a missing public key required to verify the authenticity of the repository. Addressing this issue is crucial to maintain the security and integrity of your system's package management.
GNU Privacy Guard (GPG) is a tool used for secure communication and data storage. In the context of Ubuntu's Advanced Package Tool (APT), GPG keys are employed to verify the authenticity of repositories and the packages they contain. The error message you’re encountering:
W: GPG error: http://repo.mysql.com/apt/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C
indicates that the APT system cannot verify the MySQL repository because it lacks the necessary public key identified by B7B3B788A8D3785C. Without this key, APT cannot ensure that the packages are from a trusted source, leading to the repository being disabled for security reasons.
The error message specifies the missing key ID:
B7B3B788A8D3785C
This key is essential for verifying packages from the MySQL repository. The goal is to retrieve and add this key to your system's trusted keyring.
There are multiple methods to add the missing GPG key. Below are the most effective approaches:
signed-by ApproachThis method adheres to current best practices by storing GPG keys in a dedicated keyring directory and referencing them in the repository configuration.
Create a Keyrings Directory: Ensure the directory for storing keyrings exists.
sudo mkdir -p /etc/apt/keyrings
Download and Add the GPG Key: Use curl to fetch the MySQL GPG key and store it in the keyrings directory.
curl -fsSL https://repo.mysql.com/RPM-GPG-KEY-mysql | sudo gpg --dearmor -o /etc/apt/keyrings/mysql.gpg
Update the MySQL APT Repository Configuration: Modify the repository list to use the newly added key.
echo "deb [signed-by=/etc/apt/keyrings/mysql.gpg] http://repo.mysql.com/apt/ubuntu focal mysql-8.0" | sudo tee /etc/apt/sources.list.d/mysql.list
By following these steps, you ensure that APT uses the correct key for verifying packages from the MySQL repository.
gpg DirectlyIf you prefer to import the key directly into APT's trusted keyring, follow these steps:
Download the MySQL Public Key:
wget https://repo.mysql.com/RPM-GPG-KEY-mysql -O mysql_pubkey.asc
Import the Key:
sudo gpg --no-default-keyring --keyring /etc/apt/trusted.gpg.d/mysql.gpg --import mysql_pubkey.asc
OR for older Ubuntu versions:
sudo apt-key add mysql_pubkey.asc
Remove the Temporary Key File:
rm mysql_pubkey.asc
This approach adds the MySQL GPG key to your trusted keyring, enabling APT to authenticate packages from the repository.
After adding the GPG key, ensure that the MySQL repository is correctly referenced in your APT sources. If you haven't already, you can add the repository using the following command:
sudo dpkg -i mysql-apt-config_0.8.26-1_all.deb
Note: Replace 0.8.26-1 with the latest version available from the official MySQL APT repository page.
After configuring the repository and adding the GPG key, update your package lists to apply the changes:
sudo apt update
If the GPG error is resolved, the update process should proceed without issues. You should no longer see messages indicating missing public keys.
With the repository authenticated, you can now safely install or update MySQL packages:
sudo apt install mysql-server
This command will install the MySQL server package, pulling it securely from the authenticated repository.
If the above steps do not resolve the GPG error, the issue might stem from an outdated or misconfigured repository configuration. Reconfiguring the repository can help:
Download the Latest Repository Package:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.26-1_all.deb
Install the Repository Package:
sudo dpkg -i mysql-apt-config_0.8.26-1_all.deb
Follow the on-screen prompts to select your desired MySQL version and distribution.
Update Package Lists Again:
sudo apt update
This process ensures that your system is using the latest repository configurations provided by MySQL.
Sometimes, residual data can cause authentication issues. Cleaning the APT cache and lists can help:
sudo rm -rf /var/lib/apt/lists/*
sudo apt clean
sudo apt update
This sequence removes existing package lists and clears the cache, forcing APT to retrieve fresh data.
Ensure that the MySQL repository is correctly listed in your APT sources:
cat /etc/apt/sources.list.d/mysql.list
The output should resemble:
deb [signed-by=/etc/apt/keyrings/mysql.gpg] http://repo.mysql.com/apt/ubuntu focal mysql-8.0
If discrepancies are found, adjust the file accordingly to match the correct repository URL and keyring path.
Before importing any GPG key, it's good practice to verify its fingerprint to ensure authenticity. You can obtain the fingerprint from the official MySQL documentation or their trusted channels.
Always use HTTPS when downloading GPG keys and repository packages to prevent man-in-the-middle attacks.
Only add repositories from trusted sources. Third-party repositories can pose security risks if not properly vetted.
After performing the above steps, it's essential to verify that the GPG error has been resolved:
Update the Package Lists:
sudo apt update
Ensure that the update process completes without GPG-related errors.
Install a MySQL Package:
sudo apt install mysql-server
The installation should proceed smoothly, fetching packages from the authenticated MySQL repository.
If both steps execute without errors, the GPG key issue has been successfully resolved, and you can continue managing MySQL packages securely.
The GPG error encountered while updating the MySQL repository on Ubuntu Focal is a common issue related to missing public keys necessary for authenticating package sources. By following the comprehensive steps outlined above—ranging from importing the necessary GPG key using modern methods to troubleshooting repository configurations—you can effectively resolve this error. Ensuring that your system's repositories are correctly authenticated maintains the security and integrity of your package management processes.
For further details and advanced configurations, refer to the Official MySQL APT Repository Setup Guide and the Ubuntu GPG Key Troubleshooting documentation.