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
Release: 2024-12-04 14:49:19
Original
539 people have browsed it

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
Copy after login

Exporting All Databases:

$ mysqldump -u [uname] -p --all-databases > all_db_backup.sql
Copy after login

Exporting Specific Tables in a Database:

$ mysqldump -u [uname] -p db_name table1 table2 > table_backup.sql
Copy after login

Compressing the Output:

$ mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
Copy after login

Remote Exporting:

$ mysqldump -P 3306 -h [ip_address] -u [uname] -p db_name > db_backup.sql
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template