0

I am having mysql server in centos which is running fine, i recently got a script to dump all individual databases to one folder, when i run that script to dump, i'm getting this error when ever i run the script

mysqldump: Couldn't execute 'UNLOCK TABLES': MySQL server has gone away (2006)
Db_1
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) when trying to connect
DB2

i even have /var/lib/mysql/mysql.sock in server, what is wrong, i even tried different scripts to execute my task every time i get the same problem,

but i can login using mysql -u root -p i can dump using mysqldump -u root -p db_1 > db_1.sql nothing creating problem, but only when i run through script it is creating problem

the script lines as follows,

databases=`$MYSQL --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
echo $db
$MYSQLDUMP --force --opt --user=$MYSQL_ROOT_USER --password=$MYSQL_ROOT_PASSWORD --databases $db > "$OUTPUTDIR/$db.sql"
done

please suggest solutions.

2
  • Check your logs, of course. May 15, 2015 at 15:10
  • Is your shell loop doing what you think it's doing? Check the commands it is actually sending.
    – Bert
    May 15, 2015 at 15:22

1 Answer 1

0

Seeing your error for some reason it is trying to use an incorrect unix socket.

Try adding to mysql command the parameter -S /var/lib/mysql/mysql.sock.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .