Moving a Plesk Database Between Domains
Note: I have only tried this on Plesk 8.6. If you have used this technique on any other versions of Plesk, please let us know – whether it worked the same way or not.
The Plesk web management interface is pretty cool. There are lots of sophisticated things you may want to do on a web server, but 99% of those tasks are encapsulated into the admin screens provided by Plesk; it simply gets the job done of managing web hosting.
Every now and then you will probably want to reorganise the domains, clients and databases within a server. One task includes moving a database from one domain to another.
At the server level there is no concept of a database being owned by a domain – all databases are global to the server. Within Plesk, however, each domain has its own associated databases which can only be managed from within the account that owns that domain.
To move a database to another domain, you can export it, delete the old database, create a new one in the new domain, then reimport the database. There is an easier way though.
Log into the server using ssh then issue this command to get into the MySQL command line tool:
$ mysql -u admin -p -D psa
You will need to enter your Plesk admin password.
Next take a look at the current database list:
mysql> select * from data_bases;
+----+-------------------+-------+--------+--------------+-----------------+ | id | name | type | dom_id | db_server_id | default_user_id | +----+-------------------+-------+--------+--------------+-----------------+ | 1 | consilience_db | mysql | 1 | 1 | 1 | | 2 | client1_db | mysql | 18 | 1 | 2 | | 29 | client2_db | mysql | 6 | 1 | 4 | +----+-------------------+-------+--------+--------------+-----------------+ 3 rows in set (0.00 sec)
Each database will be listed with their name and “dom_id” (domain ID). Find the ID of the database you want to move, and find the dom_id of the domain you want to move it to (the dom_id will appear in the URLs used to manage the domain in the Plesk admin screens). Then update the dom_id, for example to set database ID 29 to be owned by domain 18:
mysql> update data_bases set dom_id = 18 where id = 29;
That’s it – the database will now appear under the new domain in Plesk.
This will only work on a single server. If you are migrating between servers then there are other tools for the job.