Home >Database >Mysql Tutorial >How Can I Export a MySQL Database Dump from the Command Line?

How Can I Export a MySQL Database Dump from the Command Line?

Susan Sarandon
Susan SarandonOriginal
2024-12-04 14:49:19569browse

How Can I Export a MySQL Database Dump from the Command Line?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn