Question
How do I reinitialize MySQL or MariaDB without reinstalling the RPMs?
Answer
Warning: The steps outlined in this guide move the existing data. You will need cPanel backups or SQL dumps in order to restore your account databases through the cPanel interface or the MySQL command-line once MySQL or MariaDB has been initialized. We recommend reading through this guide in its entirety before starting the process.
cPanel support cannot assist you with these steps, and we do recommend consulting with a qualified system administrator before proceeding.
To reinitialize MySQL, perform the following steps:
-
Disable the service monitoring:
# whmapi1 configureservice service=mysql enabled=1 monitored=0
-
Stop the service:
# /scripts/restartsrv_mysql --stop
-
Check to make sure you have enough disk space to safely process the data restore. It is recommended to have over double the current MySQL data directory usage in free space.
duwill show the total usage of the MySQL data directory:# du -hs /var/lib/mysql
dfwill show the total disk usage and free space for the disk the MySQL data directory is located on:# df -h /var/lib/mysql
-
Move the directory containing MySQL. If your home data directory for MySQL is different, adjust the path accordingly:
# mv /var/lib/mysql{,.cPbak} -v && mkdir -v /var/lib/mysql && chown -v mysql. /var/lib/mysql
-
Run the initialize option for MySQL:
# mysqld --initialize --user=mysql
-
Restart MySQL again:
# /scripts/restartsrv_mysql --start
-
Re-enable the monitoring service:
# whmapi1 configureservice service=mysql enabled=1 monitored=1
-
Reset the MySQL password:
# /scripts/mysqlconnectioncheck
-
Disable the validate_password plugin option. To do this, refer to this article:
MySQL "Your password does not satisfy the current policy requirements"
- Restore the databases:
-
Through cPanel:
-
Through MySQL directly:
-
-
Restore the grants:
-
Restore database access:
-
Disable the service monitoring:
# whmapi1 configureservice service=mysql enabled=1 monitored=0
-
Stop the service:
# /scripts/restartsrv_mysql --stop
-
Check to make sure you have enough disk space to safely process the data restore. It is recommended to have over double the current MariaDB data directory usage in free space.
duwill show the total usage of the MariaDB data directory:# du -hs /var/lib/mysql
dfwill show the total disk usage and free space for the disk the MariaDB data directory is located on:# df -h /var/lib/mysql
-
Move the directory containing MariaDB. If your home data directory for MariaDB is different, adjust the path accordingly:
# mv /var/lib/mysql{,.cPbak} -v && mkdir -v /var/lib/mysql && chown -v mysql. /var/lib/mysql
-
Run the initialize option for MariaDB:
# mariadb-install-db --user=mysql
-
Restart MariaDB again:
# /scripts/restartsrv_mysql
-
Re-enable the monitoring service:
# whmapi1 configureservice service=mysql enabled=1 monitored=1
-
Reset the MariaDB password:
# /scripts/mysqlconnectioncheck
-
Disable the validate_password plugin option. To do this, refer to this article:
MySQL "Your password does not satisfy the current policy requirements"
- Restore the databases:
-
Through cPanel:
-
Through MariaDB directly:
-
-
Restore the grants:
-
Restore database access:
If the system runs CloudLinux, run the following two commands as well:
# cagefsctl -M
# cagefsctl --force-update
Comments
0 comments
Article is closed for comments.