Databases InterBase (28) MS-SQL (5) mysql (33) Oracle (1)
Exchange Links About this site Links to us
|
Exporting and importing between 2 mysql databases
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question: I need to restore a table from a mysql backup. How can I do that?
Answer: Follow these steps:
- Create a second database, here called olddb
- Assuming you have a SQL dump at hand, pass it to mysql. The backup script is called backup.sql below
- Export the table to a local file (here: /Content/tmp/data.txt)
- Leave this database and go back to your regular db
- 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';
| |  | |  |
Comments:
|