DelphiFAQ Home Search:
General :: Databases :: mysql
General information about mysql - how to get around the differences between version 3.33 an 4, how to do stuff that you think you need a nested query for etc.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Exporting and importing between 2 mysql databases

Question:

I need to restore a table from a mysql backup. How can I do that?

Answer:

Follow these steps:
  1. Create a second database, here called olddb
  2. Assuming you have a SQL dump at hand, pass it to mysql. The backup script is called backup.sql below
  3. Export the table to a local file (here: /Content/tmp/data.txt)
  4. Leave this database and go back to your regular db
  5. Do a LOAD DATA INFILE to restore your data (maybe empty that table first)

mysqladmin -uroot -pPASS create olddb
 
 mysql -uroot -pPASS olddb <backup.sql
 
 mysql -uroot -pPASS olddb
 --> 
 select * from MYTABLE into outfile '/Content/tmp/data.txt';
 
 mysql -uroot -pPASS
 --> 
 LOAD DATA INFILE '/Content/tmp/data.txt' 
 INTO TABLE MYTABLE
 FIELDS TERMINATED BY '\t'
 LINES TERMINATED BY '\n';
 

Generated 16:00:31 on May 22, 2017