Exporting MySQL Databases via the Command Line
When transitioning away from services that may require advanced system administration skills, it becomes necessary to have strategies in place for exporting data from crucial platforms. In this specific instance, we will explore how to export the contents of a MySQL database from the command line.
Solution: Employing mysqldump
To successfully extract the contents of a MySQL database, utilize the mysqldump command-line utility. By leveraging mysqldump, you can create a dump file in SQL format, encompassing either the entire database, specific databases, or particular tables within a database.
Executing mysqldump
The following examples demonstrate how to use mysqldump depending on your specific requirements:
$ mysqldump -u [uname] -p db_name > db_backup.sql
$ mysqldump -u [uname] -p --all-databases > all_db_backup.sql
$ mysqldump -u [uname] -p db_name table1 table2 > table_backup.sql
$ mysqldump -u [uname] -p db_name | gzip > db_backup.sql.gz
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p db_name > db_backup.sql
The exported .sql file will be generated in the directory where you execute the commands.
Security Enhancement
For enhanced security, avoid embedding your password directly in the command string. Instead, use the -p option followed by an empty string to prompt the system for your password without recording it.
The above is the detailed content of How Can I Export MySQL Databases from the Command Line?. For more information, please follow other related articles on the PHP Chinese website!