Import Export Mysql via ssh

Guidance to Import/Export a MySQL Database via SSH

When it comes to managing databases, MySQL is one of the most popular relational database management systems (RDBMS) out there. And while there are many ways to import and export MySQL databases, one of the most efficient ways is via SSH (Secure Shell) – a protocol used to connect securely to a remote server.

In this blog post, we’ll walk you through the steps of importing and exporting MySQL databases via SSH.

Exporting a MySQL Database via SSH

Step 1: Log in to your server via SSH

To get started, you’ll need to log in to your server via SSH. You can use a program like PuTTY or the command line if you’re on a Linux or macOS system.

Step 2: Navigate to the directory where you want to export the database

Once you’ve logged in, you’ll need to navigate to the directory where you want to export the MySQL database. You can do this using the cd command followed by the path to the directory.

Step 3: Use the mysqldump command to export the database

The mysqldump command is used to export MySQL databases. Here’s the basic syntax:

mysqldump -u [username] -p [database_name] > [filename.sql]

Replace [username] with your MySQL username, [database_name] with the name of the database you want to export, and [filename.sql] with the name you want to give the exported SQL file.

For example, if your username is root, your database name is my_database, and you want to name the exported file backup.sql, the command would look like this:

mysqldump -u root -p my_database > backup.sql

You’ll be prompted to enter your MySQL password after running the command.

Step 4: Verify that the database was exported

Once the export is complete, you can verify that the database was exported by running the ls command and checking for the file you just created.

Importing a MySQL Database via SSH

Step 1: Log in to your server via SSH

To import a MySQL database via SSH, you’ll need to log in to your server using the same method as exporting.

Step 2: Navigate to the directory where the SQL file is located

Once you’ve logged in, you’ll need to navigate to the directory where the SQL file you want to import is located. You can use the cd command followed by the path to the directory.

Step 3: Use the mysql command to import the database

The mysql command is used to import MySQL databases. Here’s the basic syntax:

mysql -u [username] -p [database_name] < [filename.sql]

Replace [username] with your MySQL username, [database_name] with the name of the database you want to import the data into, and [filename.sql] with the name of the SQL file you want to import.

For example, if your username is root, the database you want to import the data into is my_database, and the SQL file you want to import is named backup.sql, the command would look like this:

mysql -u root -p my_database < backup.sql

You’ll be prompted to enter your MySQL password after running the command.

Step 4: Verify that the database was imported

Once the import is complete, you can verify that the database was imported by logging into your MySQL client and checking the contents of the database.

Conclusion

Exporting and importing MySQL databases via SSH is an efficient and secure way to manage your databases. With these simple steps, you can easily export and import MySQL databases using only the command line, without the need for a graphical

AW Bali Digital

© 2023 awbalidigital.com by PT BIKIN INOVASI TEKNOLOGI, All Rights Reserved.