Question

I have a mysql db using innodb engine. When I do a mysqldump the table is locked and writes will fail. So I don't want to send writes to a db that is performing a mysqldump.

Is there variable I can look at that would indicate a dump is happening and the db is locked?

Was it helpful?

Solution

There's no specific variable that indicates a mysqldump is in progress. What is a mysqldump after all? It's just a SHOW CREATE TABLE <Table> and SELECT * FROM <Table> for every table. You can see these in SHOW PROCESSLIST.

For what it's worth, you don't have to lock anything as long as you're backing up only InnoDB tables. Use mysqldump --single-transaction and it will use a transaction to ensure a consistent read for the backup process, instead of locking.

See also http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_single-transaction

But to answer your question more directly, you can query a couple of places to discover current locks:


Re your comment:

Reading from a database when you're using Percona XtraDB Cluster is still just a local read. It should be fine to use mysqldump --single-transaction. It shouldn't be any different if you're using Percona XtraDB Cluster (btw, I work at Percona).

The only thing that might be affected by PXC is if you use wsrep_causal_reads, which makes reads block if there are uncommitted writesets incoming.

If you like Percona products, and you all your tables are InnoDB, you should use Percona XtraBackup, which also performs backups without locking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top