Here is how to export query result to SQL file with the help of mysqldump command: Read more mysqldump – MySQL Database Backup and restore program
mysqldump allows you to use a
WHERE clause when creating a backup and only the rows fulfilling the given condition will be included in the dump.
# Dump only the rows with the id column bigger than 1500 mysqldump my_db_name my_table_name --where="id > 1500" > my_backup.sql # Dump only the rows with the created_at column in the given interval mysqldump my_db_name my_table_name --where="date between '2022-05-01' and '2022-05-30'" > my_backup.sql
We can apply multiple condition with where clause of mysqldump. Here is the example for the same.
--where flag can be extended to contatename multiple conditions like in a normal query. The following command will dump all rows from the
users table with the
id column bigger than 1500 and the
disabled colum set to 0.
mysqldump my_db_name users --where="id > 1500 and disabled = 0" > my_backup.sql
mysqldump -u root -p testdb empdetails –where”=joiningdate between ‘2022-05-01 00:00:00’ AND ‘2022-05-30 00:00:00′” –no-create-info >jointable.sql