Exporting a MySQL Dump from the Command Line
Moving to a host with less Linux administrative control can present challenges in migrating data. Exporting a MySQL database dump from the command line can prove useful in this scenario.
To achieve this, utilize the mysqldump command-line function as follows:
Exporting an Entire Database:
$ mysqldump -u [uname] -p db_name > db_backup.sql
Exporting All Databases:
$ mysqldump -u [uname] -p --all-databases > all_db_backup.sql
Exporting Specific Tables in a Database:
$ mysqldump -u [uname] -p db_name table1 table2 > table_backup.sql
Compressing the Output:
$ mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
Remote Exporting:
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p db_name > db_backup.sql
Remember to discard passwords from command-line commands using the -p option. You will be prompted for the password without recording it. The dump file will be created in the directory where the command was executed.
The above is the detailed content of How Can I Export a MySQL Database Dump from the Command Line?. For more information, please follow other related articles on the PHP Chinese website!