How to export/import a MySQL database through SSH

November 6, 2024 / MySQL

In this article, you will learn how to export and import a MySQL database via SSH. For databases larger than 128MB, using SSH is recommended for the export/import process.

 

Follow the guide:

Make sure to replace the following placeholders in each command:

  1. USERNAME: The MySQL user for your database.
  2. DATABASE: The name of your MySQL database.

Exporting a MySQL Database

  1. To export your MySQL database, use the mysqldump command:
    mysqldump -uUSERNAME -p DATABASE > backup.sql
  2. After entering this command, you will be prompted for the MySQL user’s password. The database will be saved as “backup.sql” in your current directory.

Importing a MySQL Database

  1. To import a MySQL database, use the mysql command:
    mysql -uUSERNAME -p DATABASE < backup.sql
  2. Enter the MySQL user password when prompted. Ensure that “backup.sql” is in your current directory for a successful import.

In this manner, you can export/import a MySQL database through SSH. It is recommended for handling large databases (over 128MB) as it bypasses size limitations and provides a more efficient, secure method.

To manage databases efficiently, exporting and importing MySQL databases via SSH is a good way. Additionally if you are looking for a more user-friendly option you can use phpMyAdmin to export the database which is also a good option.

Spread the love