Thursday, May 16, 2013

InnoDB: Unable to lock ./ibdata1, error: 11

This is an error I see in the logs from time to time.  I am running a MySQL server with an openvz container on a Proxmox server.  From time to time the Proxmox server will crash which causes all the VMs it is running to stop unexpectedly (in defense of Proxmox this has only happened on a development box that is installed on a workstation).  When I attempt to access the MySQL server through the MySQL Workbench I get an error like "Can't connect to the MySQL server on <server name> (111)":
I also receive an error when trying to access the database from the command line:
# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

In the logs I found:
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
InnoDB: Error in opening ./ibdata1

I was able to fix the problem by restoring the permissions on several files (modified from this post):
# cd /var/lib/mysql
# mkdir bak
# mv ibdata1 bak/.
# mv ib_logfile* bak/.
# cp -a bak/ibdata1 ibdata1
# cp -a bak/ib_logfile* .
# service mysql restart

No comments:

Post a Comment