Problem:
Migrating away from a Linux-based server and in need of a method to export the contents of a MySQL database using the command line.
Solution:
Utilizing the mysqldump command-line function provides an efficient and straightforward solution for exporting MySQL databases. Here's how to do it:
Exporting an Entire Database:
mysqldump -u [username] -p database_name > database_backup.sql
Exporting All Databases:
mysqldump -u [username] -p --all-databases > all_databases_backup.sql
Exporting Specific Tables:
mysqldump -u [username] -p database_name table1 table2 > table_backup.sql
Auto-Compressing Output:
mysqldump -u [username] -p database_name | gzip > database_backup.sql.gz
Remote Export:
mysqldump -P 3306 -h [server_ip] -u [username] -p database_name > database_backup.sql
Notes:
The above is the detailed content of How Can I Export a MySQL Database from the Command Line?. For more information, please follow other related articles on the PHP Chinese website!