How to re-install MySQL on a WHM/cPanel server

In the future, using the website cloudhosting.lv, you agree to the rules of using Cookies. Read more. I agree

How to re-install MySQL on a WHM/cPanel server

There are some cases where you need to completely re-install MySQL or MariaDB, whether it is because the package has corrupted or is having problems or if in our case with a client you have a non-standard service installed and you are getting messages such as:

We expected to upgrade to 5.6; however, the system is currently on version 5.5. at /usr/local/cpanel/Whostmgr/Mysql/Upgrade.pm line 839. Obtained version information from system.

or

file /usr/share/man/man1/mysql_config.1.gz from install of MySQL55-devel-5.5.52-1.cp1156.x86_64 conflicts with file from package MariaDB-devel-5.5.53-1.el6.x86_64 W Error Code: 8

Unfortunately re-installing your DB packages is no easy task and can easily escalate to a nightmare, sometimes even lead to a complete disaster! So make sure you take full backups of all accounts before you begin to expect the worst case scenario of starting with a completely fresh database with no users or tables. I recommend you take backups from within WHM’s backup interface as well as taking a direct file dump of mysql’s databasedirectory which you can find at the location below:

cd /var/lib/mysql/

Once you are confident you have a fall-back plan if all goes bad you can continue with the steps below to remove all MySQL / MariaDB packages and re-install them with WHM.

Removing MySQL / MariaDB RPMs

Firstly you need to know the MySQL / MariaDB RPMs that are installed on your server. For that issue the following command:

rpm -qa | grep -i mysql

Then remove the needed MySQL / MariaDB RPMs on the server using the yum command. Below is an example, just remember to refer to the returned list above and call “yum remove x” where x is the string from each line returned above.

yum remove MySQL55-shared-5.5.37-2.cp1136.x86_64
yum remove MySQL55-devel-5.5.37-2.cp1136.x86_64
yum remove MySQL55-client-5.5.37-2.cp1136.x86_64

After that remove the mysql pid file using the following command:

rm -f /var/lib/mysql/*.pid

Re-installing MySQL / MariaDB RPMs

At last you need to install WHM / cPanel compatible database RPMs, this can be done using a single command:

/scripts/check_cpanel_rpms –fix

Now MySQL MariaDB will be re-installed based on the DB version set in WHM, finally from the MySQL/MariaDB Upgrade menu in WHM you should be able to upgrade to your preferred system and version.

Databases Missing?

If you find that all databases are now missing, you will need to unpack the backup you made of the /var/lib/mysql/ directory, hopefully this should restore everything back to normal but if this fails then you will need to restore each account from the backups one by one. This approach provides the least time depending on any resulting issues, ie. if it works it will be quick, if you can restore the manual directory backup then hardly any extra time, if it still isnt playing ball then obviously the most time consuming will be manually restoring account backups. But never underestimate a backup plan!

If you need our help to fix any issue with your server. Please feel free to contact us.