Earlier this week I was running an apt upgrade and noticed MySQL was going to update. I didn’t think twice and continued with the upgrade anyway, but I had near instant regret. After the update completed, I used the ‘mysql_upgrade’ command, as you always do after a MySQL update, and got back weird errors about how my tables were corrupted. Panicking, I tried to restart MySQL, which failed to start back up. Thankfully, I had a full backup from a few hours earlier and was back up in a few minutes. I have heard about pinning packages to a specific version, especially for databases, and I decided now would be a good time to set that up.
First, let’s see what MySQL packages we have installed. I use Percona MySQL, so I am filtering for packages containing Percona in the name.
dpkg -l | grep percona
Looking at this list, I want to hold back these packages. To do that, let’s use apt-mark’s hold command.
sudo apt-mark hold percona-server-server-5.7 percona-server-tokudb-5.7 percona-server-common-5.7 percona-server-client-5.7
Now when I run apt upgrade, these packages will be held back. This is a good idea for databases, and programs that need to run on older programming languages, but keep in mind if a package is held back it will not receive security updates or new features.
To allow a package to upgrade again, just use apt-mark unhold.
sudo apt-mark unhold percona-server-server-5.7 percona-server-tokudb-5.7 percona-server-common-5.7 percona-server-client-5.7