简体   繁体   中英

Import into MySQL from SQL file, but only rows where field = value

Is there a way from /usr/bin/mysql or /usr/bin/mysqlimport to import a sql file but exclude all rows where a specific field doesn't have a specific value?

I want to restore data from backup, but only backup data where the field "origin" has the value "import". So I have a script that first deletes all rows in the live database "where origin = 'import'" and then I want to import from a file all those rows that I have backed up, but not every single row, since there are other origins in the backup.

Am I making myself clear? Any ideas?

Two thoughts:

  1. Prepare the sqlfile by adding a where clause to each statement. Should be relatively easy with your favorite scripting language.

  2. Import to a temp "schema" and for each table:

     insert into realtable select * from temptable where origin = 'import'; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM