I have a 4GB database in MySQL. How can I back it up? Furthermore, is there a way that I can speed up the restoration process in the event that I need to recover?
I currently use a cron job every night that calls mysqldump
to dump everything and I keep 3 days of backups.
We have around 90 GB in a MySQL, so here are some suggestions:
mysqldump -u USER -pPASS --single-transaction -Q --databases foo bar
(Use the docs to check if those switches work for you.)The best way would be without interrupting normal operation. For high-reliability, fault-tolerant systems, you have 2 DBs that are kept in sync, and you backup the secondary. (eg this howtoforge article)
Otherwise, read the manual: use myseldump as you currently do, or use the mysqlhotcopy script (use just like mysqldump), or stop the DB and simply copy the frm, MID, MYI files (using rsync).
I think the stop+copy files mechanism is the fastest you're going to get.
If some of your databases are read-only or modified rarely single it out as a less frequent cron.
To answer your question - extended_insert option works good for me. If you have enough resources for restoring, extended_insert will insert huge chunks of data in a single query, making the restore faster.
You should really consider Percona's Xtrabackup
The wrapper script "innobackupex" can handle MyISAM but for a non-locking/online backup your tables should all be InnoDB.
Cheers