A cPanel account restore using the script /scripts/restorepkg immediately after the termination fails with the above message. All traces of the account including the db user are already purged from the server.
Simple Fix:
Wait some more time say 5 minutes and try once again. Most cases it will be resolved
Explanation:
When you delete an account, some parts of the deletion process (which include MySQL drop/revoke/flush stuff) are send to a queue for processing. That is, those processes don’t happen instantaneously along with the WHM interface (or API request). So, when you delete an account, the cPanel database index is queue for updating…but on cPanel account restore it attempts to recreate the account before the index has time to be rebuilt (remember it’s in a process queue), you’ll receive that error. Usually, a simple delay (10-30secs) between deletion and creation preempt this error.
If still fails
1. Check the presence of the user in the MySQL db. For that use the command below.
#mysql mysql > use mysql mysql > delete from user where user='USERNAME';
2. Check the file /etc/dbowners and grep for the username there. If so remove the corresponding entry.
3. Again grep for the username in /var/cpanel/databases/users.db and if there is a match found, remove it.
4. Finally remove the files /var/cpanel/databases/USERNAME.cache and /var/cpanel/databases/USERNAME.yaml
5. Once you are done with that, run /usr/local/cpanel/bin/setupdbmap and make sure that the files are not generated again.
Warning : DON’T execute this on older cPanel servers where the DBs have username_prefix, like in username_dbname