Restoring MySQL dumps - Importing data in sql files

Menù di navigazione
  • Home
  • Contacts
HOME | Index |

Restoring MySQL dumps

Restoring MySQL dumps

Now you've automated the running of MySQL backups with our wonderful solution [:-)]....

But now... you need to restore a specifical database from an entire mysqldump.sql file.

This solution is a bit tricky, but it's simple and uses standard commands.

First let's say we need to restore the database MyDbLost and it is in the middle of the dump file. You don't know where it is so... you need first a few variables.

With

wc -l mysqldump.sql

you'll get the number of lines of the file. The output should look like:

33815 mysqldump.sql

Write down the 33815 number. Then you have to identify where your MyDbLost begins:

grep -in "USE MyDbLost;" mysqldump.sql

And you get another line number:

5913:USE MyDbLost ;

If you don't get any result please try the following:

grep -in "USE \`MyDbLost\`;" mysqldump.sql

Now it's time to calc the lines you have to throw away from the head of your file:

33815 - 5913  + 10 = 27912

(the 10 more lines are necessary to get a little "air" between cuts)

then you can type in:

tail -n 27912 mysqldump.sql > mysqldump.1.sql

and you will get a new file called mysqldump.1.sql which starts approximately with the declarations of your database.

Now you have to trim out the queue of your file. You must identify where a new database starts:

grep -n "USE " mysqldump.1.sql | more

you'll get an output similar to:

10:USE MyDbLost ;
1339:USE MyDb1 ;
1467:USE MyDb2 ;

Take the number of lines in which is specified the second database and type

head -n 1339 mysqldump.1.sql > mysqldump.2.sql

With a little edit on mysqldump.2.sql you'll have exactly what you're looking for: the MyDbLost schema and datas!

Labs
  • CentOS + BlueQuartz
  • Installing Spamassassin ClamAv and Mailscanner on Bluequartz
  • SARE Rules & RulesDuJour
  • Installing MRTG
  • Mass Change IP
  • CCED problems
  • Deleting old logfiles
  • POP3 problems
  • Recalculate Quotas
  • How to block an IP address
  • NAMED and DNS
  • PHP
  • Enabling safe mode per-directory
  • Howto install php4 & php5 on Apache2
  • Linux
  • Automating Mysql backups
  • Restoring MySQL dumps
  • Replacing Text In Files
  • Firefox and flash on x86_64
  • Find user's files
  • Lines of code
  • Vsftp with virtual users
  • MSN
  • RandomCase

Home | Contacts | E.R.WEB Official Site