View Source

{page-title}
{excerpt}
How Does MySQL Hot Copy Work?

{excerpt} 
Lock and copy is often incorrectly called Hot Backup.  An example program that does lock and copy for MySQL is called [mysqlhotcopy|http://dev.mysql.com/doc/refman/5.0/en/mysqlhotcopy.html]

h5. How Does MySQL Hot Copy Work?

# [FLUSH TABLES WITH READ LOCK|http://dev.mysql.com/doc/refman/5.0/en/flush.html]
# Full copy of MyISAM Tables (e.g. cp or scp)
# [UNLOCK TABLES|http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html]

h5.


h5. Advantages

# Faster than a SQL Dump
 
# Restore is fast (just copy MyISAM files).

h5. Disadvantages

# Only works on MyISAM. Do NOT use with InnoDB\!
 
# Holds a global read lock on all tables blocking writes from other connections for the duration of the full backup.  Locking and Flushing is NOT optional.  There must not be any writes to the MyISAM files during the copy or they WILL BE CORRUPT.  The Flush is required to put the MyISAM files into a consistent state because mysqld caches writes to MyISAM pages in memory.
 
# The global Lock is held as long as it takes to copy all of the MyISAM files.  In pratice for larger mission critical databases this means failed queries while the database is unavailable and queries time out waiting on the lock and tyhe appication is down\!
 
# Restore is not straightforward.  You must carefully copy files back into the MySQL data directory and change permissions on them.  This can be dangerous if you make a mistake.  A less dangerous operation is to shutdown the MySQL daemon and copy MyISAM files back into the data directory

h3.