I'm trying to make backups using the mysqldump command and getting the following error or warning:
mysqldump: Got error: 1044: Access denied for user 'root'@'localhost' to database 'information_schema' when using LOCK TABLES
How do I fix this problem?
You can pass the --single-transaction option to mysqldump command:
$ mysqldump --single-transaction -u user -p DBNAME > backup.sql
Another option is to grant LOCK TABLES to your user:
$ mysql -u root -p
And type:
mysql> GRANT SELECT,LOCK TABLES ON DBNAME.* TO 'username'@'localhost';
Sample Shell Script
#!/bin/bash # Purpose: Backup mysql # Author: Vivek Gite; under GNU GPL v2.0+ NOW=$(date +"%d-%m-%Y") DEST="/.backup/mysql" # set mysql login info MUSER="root" # Username MPASS='PASSWORD-HERE' # Password MHOST="127.0.0.1" # Server Name # guess binary names MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" GZIP="$(which gzip)" [ ! -d "${DEST}" ] && mkdir -p "${DEST}" # get all db names DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=${DEST}/mysql-${db}.${NOW}-$(date +"%T").gz # get around error $MYSQLDUMP --single-transaction -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 5 comments… read them below or add one }
Gracias por la data!
I added this to automysqlbackup, let’s see tomorrow if it worked
thanks
Niiiceee) thx! It worked.
The first tip worked just fine! Thanks a lot!
Greetings!
Just getting this on newer Ubuntu and Debian machines.
The “–single-transaction” switch ruins the next switch which would be the credentials from a custom ‘~my.cf’ file.
Passing the information_schema into the ignored databases seems making the script skip it. ( Other script of Vivek’s a bit customized further).
Anyhow I would like to find a way to dump that too if there is any reason and use.
(The grant of the rights for the root user did not help. In my case root proceeds with the dump.)
Anyhow I did not investigated further yet.
– R