1. Home
  2. Technical
  3. SSH / Shell
  4. MySQL database export and import over SSH command line
  1. Home
  2. Technical
  3. MariaDB / MySQL
  4. MySQL database export and import over SSH command line

MySQL database export and import over SSH command line

How to import and export MySQL databases using SSH commands

Since there is a 2GB limit for uploading and downloading databases in the phpMyAdmin environment, and there may be errors on the web browser side, it is recommended to use the SSH command line to export and import databases more securely.

Preparation

  1. Make sure that your database user has access rights to the database you want to export or import in the My Zone MySQL/MariaDB Database management:

  2. Create an SSH connection to your virtual server. You can find instructions on how to do this here.

Database export

The database export command is:

mysqldump -uUSERNAME -p DATABASE > backup.sql

USERNAME replace with your database username
DATABASE replace with the name of the database to be exported
backup.sql is the name of the database file to be exported. If necessary, it can be changed to suit you.

After the command is run, it will ask for the user password of the database you entered. Once the password has been set, the export process begins, the time required for which depends on the size of the database.

Attention!

a) When entering a password, no symbols are displayed.
b) The exported database .sql file will end up in the same directory where you ran the command with the user.

Database import

The database import command is:

mysql -h host.mysql.zonevs.eu -uUSERNAME -p DATABASE < backup.sql

host.mysql.zonevs.eu replace with your domain MySQL server address
USERNAME
 replace with your database username
DATABASE replace with the name of the database to be exported
backup.sql is the name of the database file to import in this example. It must be located in the same directory as you are currently using.

After the command is run, it will ask for the user password of the database you entered. After entering the password, the import process begins, the time required for which depends on the size of the database.

Info

Nothing will be displayed on the command line while the import or export is in progress, a new command line will simply be created when the process completes successfully.

Updated on 18. Oct 2024
Was this article helpful?

Related Articles