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.

krisFR
  • 13,280
  • 4
  • 36
  • 42
tech2network
  • 1
  • 1
  • 3

1 Answers1

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.

alphamikevictor
  • 1,062
  • 6
  • 19