MasterServerBlog › import-export-bd-ssh

Importing / Exporting a Large Database over SSH

← all articles

If you need to import or export a really large database, PhpMyAdmin installed on the server will not solve the problem. In this case you need to turn to  command-line methods and an SSH connection.

So, first connect  to your dedicated or virtual server as the root user.

 Exporting a MySQL database over SSH

In the command line, change to any convenient folder where you want the future backup to be placed and run the command:

# mysqldump database_name --user=database_user --password=user_password > backup_dump.sql

To create a compressed database archive, run:

# mysqldump -uUSER -pPASSWORD DATABASE | gzip > /path/to/bazafile.sql.gz

where
USER - database user
PASSWORD - database user's password
DATABASE - database name
/path/to/bazafile.sql.gz - path and file name where the future backup will be stored.

Importing a MySQL database over SSH

To import a database, follow these steps:

1. Upload the database file to any convenient folder on the server.
2. Log in via SSH as root and go to the folder containing the database backup.
3. Run the import command:

# mysql -uUSER -pPASSWORD DATABASE < bazafile.sql

To import a database from an archive file:
# gzip -dc < bazafile.sql.gz | mysql -uUSERNAME -pPASSWORD DATABASE