Dumping MySQL Database Content via Query
It's not possible to perform a mysqldump by executing a single SQL query. However, the MySQL client allows you to select and export data from a database using a query.
Exporting the Entire Database
To dump all data from a database as if exporting via phpMyAdmin, execute the following command in the MySQL command-line interface:
mysql -e "select * from myTable" -u myuser -pxxxxxxxxx mydatabase
If necessary, you can redirect the output to a file for storage:
mysql -e "select * from myTable" -u myuser -pxxxxxxxx mydatabase > mydumpfile.txt
Exporting Specific Data Based on Query
Alternatively, if you wish to selectively export data based on a specific query, you can use the WHERE clause:
mysqldump --tables myTable --where="id < 1000"
This command will dump data from the specified table where the id column value is less than 1000.
The above is the detailed content of Can I Dump a MySQL Database Using Only SQL Queries?. For more information, please follow other related articles on the PHP Chinese website!