Knowledge Base

How Can We Help?

Reset MySQL Installation in cPanel

You are here:

 

There is a method to reboot MySQL setup on a cPanel server without reinstalling, but it is not recommended, because doing this will render all databases inaccessible. However, we can perform this in a critical situation such as catastrophic InnoDB corruption. In such circumstances, the intended goal is to reboot MySQL and restore from backups. Rebooting the MySQL installation is a drastic measure, so you should ensure that there is no other method to fix your problem.

Please note: cPanel does not support this MySQL server reboot.

To reboot MySQL, you need to follow the steps below.

1) First, you need to take all database backup for security. Login to the server as a root user and execute the command given below to take all database backup.

mysqldump –all-database > all_databases.sql

2) Then stop mysqld.

/etc/init.d/mysql stop

or

service mysql stop

3) Now move your mysql data directory, and /etc/my.cnf. You can create a MySQL data directory with a timestamp with the following command. If you are using another directory like /home/mysql for your mysql installation, you will need to use that directory instead, and account for this when installing a fresh database as well.

mv -v /var/lib/mysql,.Backup.`date +%F.%T`

mv -v /etc/my.cnf,.Backup.`date +%F.%T`

4) Now you will need to create the necessary mysql data directory structure with the following command.

mysql_install_db

Please note: the above command will prompt you to set a mysql root password. We will do this through WHM once mysql is running so you don’t need to set it via the command line. You will need to reset the mysql root password through WHM because otherwise, WHM will not know the root mysql password and database features will fail with access denied from mysql.

5) The next step is to set appropriate permissions on the mysql directory.

chown -R mysql.mysql /var/lib/mysql

6) Now we can start mysql service.

/etc/init.d/mysql start

or

service mysql start

7) Now you can check the mysql status by running the following command.

service mysql status

8) Then you need to reset mysql root password through WHM.

WHM >> SQL Services >> Reset MySQL Root Password

From there you can reset MySQL root password.

9) Run the following cPanel scripts to configure the cPanel mysql databases that cPanel relies on.

/usr/local/cpanel/bin/hulkdsetup

/usr/local/cpanel/bin/update-roundcube –force

/scripts/fullhordereset –force

/usr/local/cpanel/bin/leechprotectinstall –force

/usr/local/cpanel/bin/update-logaholic –force

10) Finally, you need to restore the databases from the backup and run the following command to restore the grants to the database, if you add databases back in for the users. This will restore all the cPanel grants and allow access to the databases.

/usr/local/cpanel/restoregrants –db=mysql –cpuser=USERNAME –all

 

If you need any further assistance, please do reach our support department.

 

Leave a Comment