问题
Is it possible to backup a MySQL Table with a WHERE Condition?
For example,
I have a table with a date AND time column.
Now I want to backup that table with date >= '2013-08-01'.
What I have in mind is to SELECT the data I needed to a temporary table then backup that temporary table.
Is there any other way?
回答1:
TRY this :
$db_user = "username";
$db_pass = "password";
exec("mysqldump --opt -u$db_user -p$db_pass --no-create-info --where date >= '2013-08-01' my_database my_table > backup.sql");
回答2:
this may help you try this In order for this to work, you will need to copy mysqldump.exe and mysql.exe from the MySQL bin Program Files folder into the same directory as your executing PHP script. If you know the direct path to these for your server, you can use those instead.
// Config
$db_user = "db_username";
$db_pass = "db_pass";
// Dump an entire database
exec("mysqldump --opt -u$db_user -p$db_pass my_database > backup.sql");
// Dump a table
exec("mysqldump --opt -u$db_user -p$db_pass my_database my_table > backup.sql");
// Dump just table rows without structure
exec("mysqldump --opt -u$db_user -p$db_pass --no-create-info my_database my_table > backup.sql");
// Dump just table rows with WHERE clause without structure
exec("mysqldump --opt -u$db_user -p$db_pass --no-create-info --where=id='1' my_database my_table > backup.sql");
// Restoring from .sql file
exec("mysql -u$db_user -p$db_pass my_database < backup.sql");
Note. Where the exec() function starts with mysqldump; you could replace it with C:Program FilesMySQLbinmysqldump.exe for example if you are not permitted to copy the two required files from the bin folder.
回答3:
Yes it is possible to backup a MySQL Table with a WHERE Condition
Try the below Query
select * --specify column name or back up every column
into back_up_table
from table_name
where date >= '2013-08-01'
来源:https://stackoverflow.com/questions/18372013/mysql-backup-with-where-condition