2

I want to dump data from my table by certain criteria, here is the sql query:

"SELECT * FROM document WHERE date BETWEEN 20160101 AND 20160131"

Table that I am selecting from is MyISAM Merge.

I have deleted rows that are matching that query, and I want to import them back from backup, but only those rows.

I have tried making dump like this:

mysql -uroot -proot mydb -e "SELECT * INTO OUTFILE '/tmp/doc.sql' from document WHERE date BETWEEN 20160101 AND 20160131".

But it will generate a file that can not be imported by phpmyadmin import tool. And yet again PMA does not want to do any export of this query result.

Any help ? I can not post structure of the real database/table because of NDA.

EDIT: for all that are having trouble dumping data from MyISAM MRG table, you need to dump from the subtable, not the main one.

1
  • what code do you use and what error(s) do you get when trying to import? is it it imperative that you use phpmyadmin? have you tried importing with anything else, such as command line? try looking at outfile, and considee using quotations to deal with newline issues if relevant.
    – hilcharge
    Feb 12, 2016 at 12:35

2 Answers 2

4

If be honest i don't use phpmyadmin at all and phpmyadmin import tool, but i know how it can be done in shell:

1st step - export dump:

mysqldump -uUSER -pPASS \
--databases DB_NAME --tables document \
--where 'date BETWEEN 20160101 AND 20160131' \
--no-create-info > document.dump.sql

2nd step - import dump:

mysql -uUSER -pPASS -DDB_NAME < document.dump.sql

Suppose you have access to shell where db is located and i hope it'll be helpful for you...

1
  • I have noticed that when you work with Merged MyISAM tables, you need to dump from the subtable in order to get data dumbed. That is why I can not accept your anwer because it is not complete, but tbh, dunno what to do :D Feb 12, 2016 at 14:49
3
mysqldump -uroot -proot mydb document --where="date BETWEEN 20160101 AND 20160131" > dump.sql

mysql -uroot -proot mydb < dump.sql
3
  • I have noticed that when you work with Merged MyISAM tables, you need to dump from the subtable in order to get data dumbed. That is why I can not accept your anwer because it is not complete, but tbh, dunno what to do :D Feb 12, 2016 at 14:48
  • you need ignore foreign key, you insert data but after you need import other tables with foreign values! cat <(echo "SET FOREIGN_KEY_CHECKS=0;") dump.sql | mysql Feb 14, 2016 at 0:39
  • Worth noting that this will drop and recreate the table, which I did not understand to be the required outcome(although reading back, it's unclear). To only export the data, add --no-create-info to the export.
    – Louis M.
    May 24, 2022 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.