Skip to content

Resetting a forgotten MySQL root password on a cPanel server without breaking the cPanel daemon

cPanel stores the MySQL root password in `/root/.my.cnf` and uses it for every internal MySQL operation. Resetting the password without updating cPanel's copy breaks the next cPanel update.

A cPanel server has lost its MySQL root password — someone rotated it manually, the password manager entry is gone, or the server was inherited and the previous admin never wrote it down. The standard MySQL “skip-grant-tables” recovery works, but if you stop there, cPanel’s daemons stop being able to log into MySQL on their next cycle and the host degrades over the next 24 hours. The right reset updates both MySQL and cPanel’s stored credentials.

What’s happening

cPanel stores the MySQL root password in /root/.my.cnf (a standard MySQL client config). It uses this for whmapi1 operations, the MySQL/MariaDB Upgrade tool, backup invocations, and the dbmap maintenance routines. Resetting the password in MySQL without updating /root/.my.cnf leaves cPanel pointing at a stale password — the next whmapi1 list_dbs call fails, and cascading failures follow.

cPanel does have a built-in command for this: /usr/local/cpanel/bin/cpmysql-reset-password. It generates a new password, updates MySQL, and writes the new password to /root/.my.cnf atomically. Use it whenever possible. The manual procedure below is only for cases where the cPanel command itself can’t run (MySQL is broken in some way that prevents it from logging in).

How to verify

mysql -e "SELECT VERSION()" 2>&1 | head
ls -la /root/.my.cnf
cat /root/.my.cnf  # contains the current password
ps aux | grep -E "mysqld|mariadbd"
systemctl status mariadb

If mysql -e returns a result without prompting for password, root authentication is currently working (you just don’t know the password) — use the cPanel command. If mysql -e prompts for password or fails to connect, you’re in the manual path.

The fix

Preferred: use the cPanel command.

/usr/local/cpanel/bin/cpmysql-reset-password

It does everything: stops MySQL, generates a strong password, restarts MySQL, updates /root/.my.cnf. Verify by running mysql -e "SELECT 1" and whmapi1 list_dbs.

Manual procedure when the cPanel command can’t run:

  1. Stop MySQL: systemctl stop mariadb.
  2. Start MySQL with grant tables disabled:
    mysqld_safe --skip-grant-tables --skip-networking &
    This bypasses the privilege system and lets you connect without a password. --skip-networking keeps the daemon on the socket, no TCP — important so nobody else connects during the window.
  3. Connect and reset:
    mysql -u root
    FLUSH PRIVILEGES;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-strong-password';
    FLUSH PRIVILEGES;
    The FLUSH PRIVILEGES before the ALTER is required when started with --skip-grant-tables so MySQL re-reads the grant tables.
  4. Stop the bypass instance and start normally:
    killall mysqld
    systemctl start mariadb
  5. Test the new password:
    mysql -u root -p
    Enter the new password. If it works, proceed.
  6. Update /root/.my.cnf:
    /root/.my.cnf:
    [client]
    user=root
    password=new-strong-password
    chmod 600 /root/.my.cnf so only root can read it. Without this step, cPanel’s internal calls keep using the old password and fail.
  7. Restart cPanel daemons so they pick up the new credential:
    /scripts/restartsrv_cpsrvd
  8. Verify cPanel still works:
    whmapi1 list_dbs | head
    whmapi1 list_users | head
    /scripts/dbmap_check

For takeover scenarios where the inherited password is unknown and you don’t trust the existing state, Stack Harbor’s cPanel server administration team runs the cPanel reset command as part of the standard intake checklist and rotates credentials into a password manager so the next person doesn’t repeat the exercise.