- Plesk for Windows
- 3 Plesk servers: SourcePlesk, SecondaryPlesk and TargetPlesk.
- 2 Remote Database servers: DBS1 and DBS2
- SourcePlesk is attached to DBS1, SecondaryPlesk and TargetPlesk are attached to DBS2.
- SourcePlesk has a subscription example.com with database 'db1' and database user 'dbuser1'
- SecondaryPlesk has a subscription example2.com with database 'db1' and database user 'dbuser1'
When migrating example.com from SourcePlesk to TargetPlesk the following error is displayed in Plesk:
PLESK_ERROR: During migration the following error occurs:
Unable to create database 'db1' in subscription 'example.com': Command LANG=en_US.UTF-8 ALLOW_WEAK_PASSWORDS=1 PLESK_RESTORE_MODE=1 database --create db1 -domain example.com -skip-webspace-checking -type mysql -server 192.0.2.2:3306 -ignore-nonexistent-options failed with exit code 2:
stderr: Database with requested name already exists.
Unable to create database user 'dbuser1' in subscription 'example.com': Command LANG=en_US.UTF-8 ALLOW_WEAK_PASSWORDS=1 PLESK_RESTORE_MODE=1 PSA_PASSWORD=***hidden*** database --create-dbuser dbuser1 -passwd ***hidden*** -domain example.com -database db1 -type mysql -server 192.0.2.2:3306 -ignore-nonexistent-options failed with exit code 1:
stderr: Unable to add database user: Operation CREATE USER failed for 'dbuser1'@'%'
The issue is submitted as a bug PMT-4366 which is planned to be fixed in one of the future Plesk updates.
Note: This workaround has one dangerous moment and it is strongly recommended to create full database server backups prior to migration, be very attentive and first try it in test environment.
- Log in to Plesk
- On the target server create a fake subscription(i.e. fake.sub).
- Connect to target server using SSH and fetch its id from psa database with the query:
# plesk db -e "select id from domains where name='fake.sub';"
| id |
| 22 |
1 row in set (0.00 sec)
- Fetch DBS2 database server id from psa database on the target server:
# plesk db -e "select id from databaseservers where host='DBS2';"
| id |
| 3 |
1 row in set (0.00 sec)
- Get the list of all databases which are present on the remote target MySQL server(DBS2) (using SHOW DATABASES), but not registered on the target psa database (check "data_bases" table of "psa" database).
- Get the list of all db_users which are present on the remote target MySQL server(DBS2) (using select user from mysql.user;), but not registered on the target psa database (check db_users table of "psa" database).
- Put all of the databases fetched from step 3 to "data_bases" table linking them to the fake subscription and all of the database users fetched from step 4 to db_users table linking them to the fake subscription on the target server:
# plesk db -e "insert into data_bases (name, type, dom_id, db_server_id) values('db1','mysql',22,3);"
# plesk db -e "insert into db_users (login,dom_id,db_server_id) values ('dbuser1',22,3);"
Warning: From that moment do not remove the fake subscription until it has databases in data_bases table and in Plesk interface.
- Perform migration - migrator must rename all migrated databases and adjust wp-config.php.
- Once migration is finished:
- remove fake records from "data_bases" table.
- make sure that the fake subscription does not have any databases.
- remove the fake subscription.