When started with the --log-update=file_name
option, mysqld
writes a log file containing all SQL commands that update data. The file is
written in the data directory and has a name of file_name.#
, where
#
is a number that is incremented each time you execute
mysqladmin refresh
or mysqladmin flush-logs
, the FLUSH
LOGS
statement, or restart the
server.
If you use the --log
or -l
options, the filename is
`hostname.log', and restarts and refreshes do not cause a new log file
to be generated. By default, the mysql.server
script starts the
MySQL server with the -l
option. If you need better
performance when you start using MySQL in a production environment,
you can remove the -l
option from mysql.server
.
Update logging is smart since it logs only statements that really update
data. So an UPDATE
or a DELETE
with a WHERE
that finds no
rows is not written to the log. It even skips UPDATE
statements that
set a column to the value it already has.
If you want to update a database from update log files, you could do the
following (assuming your log files have names of the form
`file_name.#'):
shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
ls
is used to get all the log files in the right order.
This can be useful if you have to revert to backup files after a crash
and you want to redo the updates that occurred between the time of the backup
and the crash.
You can also use the update logs when you have a mirrored database on
another host and you want to replicate the changes that have been made
to the master database.