MySQL is one of the most popular open-source database management systems available today. In this blog, we will walk through the steps to export and import MySQL databases using the command line. This method is particularly useful for those who prefer using the command line interface (CLI) over graphical user interfaces (GUI).

Step 1: Open Command Line Interface (CMD)

Open the command line interface on your computer. On Windows, you can do this by searching for “cmd” in the start menu and clicking on the ‘Command Prompt’.

Step 2: Navigate to the MySQL Bin Directory

Navigate to the bin directory of your MySQL installation. If you have installed XAMPP on your Windows machine, the bin directory is usually located at C:\xampp\mysql\bin.

cd C:\xampp\mysql\bin

Step 3: Export the MySQL Database

To export the MySQL database, you will use the mysqldump command followed by the -u option (for specifying the username), the -p option (which will prompt you for the password), and the name of the database you want to export. The > operator is used to redirect the output to a file.

mysqldump -u username -p database_name > data-dump.sql

Replace username with your MySQL username and database_name with the name of the database you want to export. You will be prompted to enter your MySQL password.

Step 4: Import the MySQL Database

To import the MySQL database, you will use the mysql command followed by the -u option (for specifying the username), the -p option (which will prompt you for the password), and the name of the database you want to import. The < operator is used to redirect the input from a file.

mysql -u username -p database_name < data-dump.sql

Replace username with your MySQL username and database_name with the name of the database you want to import. You will be prompted to enter your MySQL password.

Conclusion

Exporting and importing MySQL databases via the command line is a straightforward process that involves only a few steps. By mastering these steps, you can easily transfer your databases from one server to another.

0 Comments

Leave a Comment