A cPanel customer logs into MySQL Databases and sees a database they don’t own, or doesn’t see one they do. The application works fine — credentials are correct, queries succeed — but the cPanel UI is confused. Backups for the account skip the missing database. WHM > List Accounts shows wrong database counts. The dbmap (cPanel’s per-account database registry) has drifted from MySQL’s actual grant tables. dbmaprepair is the tool that reconciles them, but running it without understanding what it does can re-introduce permissions that you deliberately revoked.
What’s happening
cPanel stores per-account database metadata in two places:
/var/cpanel/databases/<user>.json(newer format) or/var/cpanel/databases/users.db.cache(older).- MySQL grant tables:
mysql.user,mysql.db,mysql.tables_priv.
cPanel maintains both. When they diverge, it’s usually because:
- Someone ran raw GRANT or DROP USER as MySQL root, bypassing cPanel.
- A database was created or dropped directly via mysql, not via the API/UI.
- An account was moved between servers and the dbmap copy didn’t.
- A failed JetBackup restore left partial state.
dbmaprepair rebuilds the dbmap from MySQL’s actual state. It does NOT modify MySQL — it brings the cPanel view into agreement with MySQL. So if MySQL has a grant that shouldn’t be there (legacy user nobody remembered to drop), dbmaprepair writes it into the dbmap as a legitimate grant.
How to verify
whmapi1 list_dbs user=acmecorp
ls -la /var/cpanel/databases/acmecorp.*
mysql -e "SHOW DATABASES LIKE 'acmecorp\\_%'"
mysql -e "SELECT User, Host FROM mysql.user WHERE User LIKE 'acmecorp\\_%'"
mysql -e "SELECT Db, User, Host FROM mysql.db WHERE User LIKE 'acmecorp\\_%'"
/scripts/dbmap_check # cPanel's own check
Compare what whmapi1 says the account owns to what MySQL actually has. Differences are dbmap drift. dbmap_check runs cPanel’s verification; it reports inconsistencies but doesn’t fix them.
The fix
- Take backups first — both filesystem and a mysqldump:
cp -r /var/cpanel/databases/ /backup/dbmap-$(date +%F)/ mysqldump --all-databases --single-transaction | gzip > /backup/mysql-$(date +%F).sql.gz - Audit the discrepancy. Before running
dbmaprepair, understand which way the drift goes:- dbmap missing items that MySQL has: someone created a database/user directly in MySQL, cPanel didn’t know.
- dbmap has items MySQL doesn’t: someone dropped a database/user directly in MySQL, cPanel still thinks it exists.
- Both have the same items but with different permissions: cPanel says ALL, MySQL says SELECT only (or vice versa).
- For drift caused by raw MySQL operations, decide whether to keep the MySQL state or restore the cPanel state:
- If a customer asked for a privilege removed and someone did it via raw SQL, you want to keep MySQL state — run
dbmaprepair. - If a runaway script created users you don’t recognize, you want to remove them from MySQL, then run
dbmaprepairto clean dbmap.
- If a customer asked for a privilege removed and someone did it via raw SQL, you want to keep MySQL state — run
- Repair the dbmap for one user:
Inspects MySQL’s grants for/usr/local/cpanel/bin/dbmaprepair --user=acmecorpacmecorp_%users and writes them into the dbmap. Existing dbmap entries that don’t match are overwritten. - Repair for all users:
Iterates over all accounts. Heavy on a host with hundreds of users — runs for several minutes./usr/local/cpanel/bin/dbmaprepair - Verify post-repair:
The check should report clean. The list should match MySQL’s reality.whmapi1 list_dbs user=acmecorp /scripts/dbmap_check - For “the customer wants a database back that I dropped” — restore from JetBackup (separate article).
dbmaprepaironly reconciles the registry; it doesn’t recover data. - For prevention, never run raw GRANT, CREATE USER, DROP USER, CREATE DATABASE, DROP DATABASE against
acmecorp_%namespace from root mysql. Useuapiorwhmapi1. This is documented in the grants article but bears repeating — every dbmap repair is downstream of someone bypassing the API.
For environments where dbmap drift is suspected across many accounts, Stack Harbor’s WHM server management team runs dbmap_check on a scheduled cadence and audits the diffs against expected state before repair, so legitimate state changes aren’t silently overwritten.