How to manually import or export a MySQL database via command line (Plesk - Linux)

 

Exporting

 

If you use the Plesk control panel and are having issue exporting via PHPMyADMIN (Due to errors or too large a SQL file) then you can do the following to export the database

1. Log in to the server via SSH

2. Type the following:

  • mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` NAME_OF_DB > NAME_OF_DB.sql

This will output the database to a file named NAME_OF_DB.sql

You can also output this to a websites root folder by changing the NAME_OF_DB.sql to /var/www/vhosts/example.co.uk/NAME_OF_DB.sql

Once done, the database will be backed up to the specified SQL file.

 

Importing


Once you have a SQL file you can import it using the following steps:

1. Log into the server via SSH

2. Type the following:

  • mysql -uadmin -p`cat /etc/psa/.psa.shadow` NAME_OF_DB < /path/to/NAME_OF_DB.sql

 

Please note that the database must have already been created via Plesk and must be empty for this to work.

 

1. Log in to the server via SSH

2. Type the following:

  • mysql -uadmin -p`cat /etc/psa/.psa.shadow` NAME_OF_DB > NAME_OF_DB.sql