To import and export a MySQL database, you can use the command-line tool called mysqldump
. This tool allows you to create a backup of a database, which can then be imported or exported to/from another MySQL server.
Here’s how you can import and export a database using mysqldump
:
Export/Backup a MySQL Database:
- Open a terminal or command prompt.
- Navigate to the location where you want to save the backup file (e.g.,
cd /path/to/backup/folder
). - Use the following command to export the database to a SQL file:
Import Mysql Database
$ mysql -u USERNAME -p DB_NAME < import_file.sql
Password:
Export Mysql Database
$ mysqldump -u USERNAME -p DB_NAME > exported.sql
Password:
That’s it! You have successfully imported/exported a MySQL database using mysqldump
.