Disable Table Locking in mysqldump
May 21st, 2008 at 9:46 pm (Technology, Windows, cross-platform)
I have a cron job on a web server that periodically runs mysqldump and emails me a zip file containing the database backups. I looked at one of them recently, and instead of the full DB dump, all it had in was this:
-- MySQL dump 10.11 -- -- Host: localhost Database: dbname -- ------------------------------------------------------ -- Server version 5.0.37-standard-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE ='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
…and when I try running sqldump from the command line I get:
mysqldump: Got error: 1044: Access denied for user ‘usrname’@'%’ to database ‘dbname’ when using LOCK TABLES
After lots of fruitless Googling, I came across this page, which says the problem can be overcome by using the “–skip-lock-tables” flag, like this:
mysqldump --skip-lock-tables -u usrname -p dbname > backup.sql
Worked perfectly!