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

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

Linda Hamilton
Release: 2024-12-05 00:47:11
Original
232 people have browsed it

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

Exporting MySQL Database from Command Line

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

Exporting All Databases:

mysqldump -u [username] -p --all-databases > all_databases_backup.sql
Copy after login

Exporting Specific Tables:

mysqldump -u [username] -p database_name table1 table2 > table_backup.sql
Copy after login

Auto-Compressing Output:

mysqldump -u [username] -p database_name | gzip > database_backup.sql.gz
Copy after login

Remote Export:

mysqldump -P 3306 -h [server_ip] -u [username] -p database_name > database_backup.sql
Copy after login

Notes:

  • Use -p option without specifying password for security reasons. It will prompt for user input.
  • The SQL file will be saved in the current working directory.
  • It's recommended to replace placeholders ([username], [database_name], etc.) with actual values.

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!

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