Backup restore or migration fails. Unable to create database user: User with requested name already exists

Refers to:

  • Plesk 12.5 for Linux
  • Plesk 11.5 for Windows
  • Plesk 11.5 for Linux
  • Plesk 12.0 for Windows
  • Plesk 12.0 for Linux
  • Plesk 12.5 for Windows

Created:

2016-11-16 12:55:58 UTC

Modified:

2016-12-21 19:34:02 UTC

0

Was this article helpful?


Have more questions?

Submit a request

Backup restore or migration fails. Unable to create database user: User with requested name already exists

Symptoms

Backup/restore or migration failed with the following error:

Warning: database "DB_NAME"

Failed deployment of database user USER_NAME of database DB_NAME

Warning:

Execution of /usr/local/psa/admin/plib/api-cli/database.php --update events -add_user USER_NAME -server localhost:3306 -type mysql -print-id -default -set-acl % -passwd '' -passwd_type sym -ignore-nonexistent-options failed with return code 1.
Stderr is
Unable to create database user: User with requested name already exists

Cause

User with requested name already exists.

  • Database was not completely removed after previous failed attempts.
  • The same username is used for another database.

Resolution

  1. Backup psa and mysql databases # 213904125

  2. Login to Plesk database # 213928465 and ensure that the user USER_NAME is not used by any other databases in Plesk

    mysql> select db.name as 'DB Name', u.login as 'DB User' from data_bases db, db_users u where db.default_user_id=u.id and u.login='USER_NAME';

2.1 If previous step showed that there is no any database connected then:

    mysql> delete from mysql.user where User='USER_NAME';
mysql> delete from mysql.db where User='USER_NAME';
mysql> FLUSH PRIVILEGES;
mysql> delete from psa.db_users where login='USER_NAME';

Also remove user from mysql database:

    mysql> SELECT Host,User FROM mysql.user where User='USER_NAME';
+-----------+-----------+
| Host | User |
+-----------+-----------+
| localhost | USER_NAME |
+-----------+-----------+

mysql> DROP USER 'USER_NAME'@'localhost';

2.2 If an user with the same username manages another database on the server run the following to get conflicting database and domain name:

    mysql> select name from domains where id in (select dom_id from data_bases where id in (select db_id from db_users where login ='username'));

mysql> select name from data_bases where id in (select db_id from db_users where login ='username');

On the domain management page go to Databases , select required database and change username to another.

Have more questions? Submit a request
Please sign in to leave a comment.