I have an InnoDB MySQL database. When I export a SQL dump, how does the locking occur? Does the entire database lock during the export? Or just the table? Or just the individual rows? How exactly does the export work with InnoDB?
I have an InnoDB MySQL database. When I export a SQL dump, how does
Share
You can control what is locked.
To be safest, you can lock all tables like this:
Docs: Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off –single-transaction and –lock-tables.
Or if you’re sure you’re not going to alter tables:
Docs: While a –single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log coordinates), no other connection should use the following statements: ALTER TABLE, CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A consistent read is not isolated from those statements, so use of them on a table to be dumped can cause the SELECT that is performed by mysqldump to retrieve the table contents to obtain incorrect contents or fail.