I have a mysqldump backup of my mysql database consisting of all of our tables which is about 440 megs. I want to restore the contents of just one of the tables form the mysqldump. Is this possible? Theoretically, I could just cut out the section that rebuilds the table I want but I don't even know how to effectively edit a text document that size.
相关问题
- php PDO::FETCH_ASSOC doesnt detect select after ba
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
You can try to use sed in order to extract only the table you want.
Let say the name of your table is
mytable
and the file mysql.dump is the file containing your huge dump:This will copy in the file
mytable.dump
what is located betweenCREATE TABLE mytable
and the nextCREATE TABLE
corresponding to the next table.You can then adjust the file
mytable.dump
which contains the structure of the tablemytable
, and the data (a list ofINSERT
).This tool may be is what you want: tbdba-restore-mysqldump.pl
https://github.com/orczhou/dba-tool/blob/master/tbdba-restore-mysqldump.pl
e.g. Restore a table from database dump file:
You should try @bryn command but with the ` delimiter otherwise you will also extract the tables having a prefix or a suffix, this is what I usually do:
Also for testing purpose, you may want to change the table name before importing:
To import you can then use the mysql command:
Get a decent text editor like Notepad++ or Vim (if you're already proficient with it). Search for the table name and you should be able to highlight just the CREATE, ALTER, and INSERT commands for that table. It may be easier to navigate with your keyboard rather than a mouse. And I would make sure you're on a machine with plenty or RAM so that it will not have a problem loading the entire file at once. Once you've highlighted and copied the rows you need, it would be a good idea to back up just the copied part into it's own backup file and then import it into MySQL.
The chunks of SQL are blocked off with "Table structure for table
my_table
" and "Dumping data for tablemy_table
."You can use a Windows command line as follows to get the line numbers for the various sections. Adjust the searched string as needed.
find /n "for table `" sql.txt
The following will be returned:
---------- SQL.TXT
[4384]-- Table structure for table
my_table
[4500]-- Dumping data for table
my_table
[4514]-- Table structure for table
some_other_table
... etc.
That gets you the line numbers you need... now, if I only knew how to use them... investigating.
You can use vi editor. Type:
to open both whole dump
mysql.dump
and a new filemytable.dump
. Find the appropriate insert into line by pressing/
and then type a phrase, for example: "insert into `mytable`", then copy that line usingyy
. Switch to next file byctrl+w
thendown arrow key
, paste the copied line withpp
. Finally save the new file by typing:wq
and quite vi editor by:q
.Note that if you have dumped the data using multiple inserts you can copy (yank) all of them at once using
Nyy
in whichN
is the number of lines to be copied.I have done it with a file of 920 MB size.