top of page
Writer's pictureRahul R

How to import and export a MySQL Database via Terminal

Importing and exporting MySQL databases via the terminal is a quick and efficient way to backup or transfer your data between different servers or hosting environments. In this blog post, we will discuss the steps for importing and exporting MySQL databases using the command line.


Exporting a MySQL Database via Terminal: To export a MySQL database, you will need to use the mysqldump command. The syntax for this command is as follows:


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


Replace [username] with your MySQL username, [database_name] with the name of the database you want to export, and [backup_file.sql] with the name you want to give to your backup file. The ‘>’ symbol is used to redirect the output to the backup file.


Example:


mysqldump -u root -p my_database > my_database_backup.sql


This command will create a backup file named my_database_backup.sql in the current directory.


Importing a MySQL Database via Terminal: To import a MySQL database, you will need to use the mysql command. The syntax for this command is as follows:


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


Replace [username] with your MySQL username, [database_name] with the name of the database you want to import the data into, and [backup_file.sql] with the name of the backup file that contains the data. The ‘<’ symbol is used to read the input from the backup file.


Example:


mysql -u root -p my_database < my_database_backup.sql


This command will import the data from my_database_backup.sql into the my_database database.

26 views0 comments

Recent Posts

See All

Comments


bottom of page