Wednesday, December 28, 2011

"Using Lock tables" error while taking Mysqldump

This is the comman error which we get while taking the mysqldump of large databases.

File './databasename/tablename.MYD' not found (Errcode: 24) when using LOCK TABLES

If you will print the system error code 24 by using perror, it will return  "OS error code  24:  Too many open files"
This error can be resolve in several ways -
1- set open-files-limit=10000(or any higher number)
or define open-files-limit and open_files_limit in configuration files.

Note- if you are using MySQL version < 5.1.52. only use open-files-limit don't use open_files_limit. In these version open_files_limit can't set limit higher than 65535. But for newer version these issues are fixed.

2- By using --single-transaction with mysqldump i.e - mysqldump --single-transactions -uroot -p database>database.sql
    This option sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB and BDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications.
    When using this option, you should keep in mind that only InnoDB tables are dumped in a consistent state. For example, any MyISAM or MEMORY tables dumped while using this option may still change state.(src -http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html)
   
3- while taking the mysql dump, use –-lock-tables=false option. But remember it is not recomended for innoDB engines

Every dumped database, lock all tables to be dumped before dumping them. These tables locked to allow  concurrent inserts in the case of MyISAM tables with READ LOCAL . In case of Innodb (transactional) tables, --single-transaction better than --lock-tables because it does not need to lock the tables.

Since this option locks tables for each database separately, it is not guaranteed that the tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states