Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm writing a shell script wherein I'm doing a mysqldump of all databases.

My questions are:

  1. Are the tables of all databases in the server locked during the mysqldump?
  2. If I have to do an incremental backup using mysqlbinlog from the last full backup, should I take the time when mysqldump started or when it ended?
  3. What happens when one is using the database when mysqldump is running? How can I take the start time for mysqlbinlog? What happens when mysqldump is executed?
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Let me address each of your three Questions

QUESTION #1

Are the tables of all databases in the server locked during the mysqldump?

ANSWER TO QUESTION #1

Depends on the default settings you allow and what setting you use to override. The --opt parameter is enabled by default. That enables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.

If you have a database with all InnoDB tables or a mix of InnoDB tables and read-only MyISAM tables, you can just use --single-transaction. This will create a clean point-in-time snapshot of all tables involved in the mysqldump. Any INSERT/UPDATE/DELETE queries against an InnoDB table will not interfere with the point-in-time consistency of the mysqldump.

By the way, --single-transaction is mutually exclusive to --lock-all-tables. Thus, using --single-transaction will disable --lock-all-tables.

QUESTION #2

If I have to do an incremental backup using mysqlbinlog from the last full backup, should I take the time when mysqldump started or when it ended?

ANSWER TO QUESTION #2

You could take the time if you do mysqlbinlog at different times of the day. You could save yourself some off that housekeeping information by simply running FLUSH LOGS; or FLUSH BINARY LOGS; the same time every night. For example, you could script a cronjob to run FLUSH LOGS;at 11:59 PM like this

#!/bin/sh
sleep 55
mysql -uroot -p... -e"FLUSH LOGS;"

That way you can logically group together all binary logs that have the same date when formulating any needed incremental backup.

You do not have record times or positions in this respect: If you include the option --master-data=2 in the mysqldump, the log file and position at recorded as a comment on line 22 of the mysqldump output.

QUESTION #3

What happens when one is using the database when mysqldump is running? How can I take the start time for mysqlbinlog? What happens when mysqldump is executed?

ANSWER TO QUESTION #3

Here is where you have to be very careful. As I mentioned earlier, if you have a database with all InnoDB tables or a mix of InnoDB tables and read-only MyISAM tables, you can use --single-transaction and every table involved in the mysqldump will exist in the same point-in-time.

What Can Go Wrong #1

If you are performing INSERT/UPDATE/DELETE queries against a MyISAM table during the mysqldump, then the MyISAM tables will not be point-in-time consistent.

What Can Go Wrong #2

If you are performing ALTER TABLE, DROP TABLE, RENAME TABLE, or TRUNCATE TABLE against any table (MyISAM or InnoDB), consistent mysqldumps are no longer isolated. The transaction you issued with --single-transaction is released (made null and void) and all tables afterward can no longer the point-in-time consistent.

If one of these occur, recording start times or position is rendered useless.

share|improve this answer
  1. you can use --lock-tables to lock all tables in the current dumped database or --lock-all-tables which will lock all tables in all databases. if you don't want to lock the tables at all, you can use skip-lock-tables.

  2. to do an incremental backup, you must use the command SHOW MASTER STATUS; and take note of the Binlog File and Position, you can see an tutorial in here

  3. I believe this question is related to restore the transactions from binlog after the dump, in this case, you just need to run the binarylog starting the position you took during the dump

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.