After some maintenance was done to the virtual host server that one of my virtual servers was running on that required a host reboot, my websites weren't running due to the MySQL error "[ERROR] /usr/sbin/mysqld: Can't open file: './databasename/tablename.frm' (errno: 24)"
In my case, the issue was due to too many files being open. Increasing the open_files_limit setting and restarting MySQL fixed the issue. It's quite possible this error message will also occur for other reasons (e.g. file corruption), but in my case it was the file limit issue.
Longer answer
After working out it was not an issue with the web server (Nginx) or PHP, I checked the MySQL error log, which was full of messages like this (where "databasename" was the name of the database, and "tablename" was the name of the table):
I was able to log into the MySQL command line and run a query against a database, and got the same sort of error message:
After some Googling around, I found that the issue might be due to the open files limit setting not being high enough. You can check what the current setting is with this query, and result:
And then see how many files are currently open:
Judging from the above result, I did actually have a high enough open files limit, but it was worth attempting to change the setting to see if it fixed the problem, seeing as the number of open files wasn't too far off the limit. I also found myself unable to subsequently open up a MySQL command prompt again.
Increasing the open_files_limit setting
The open_files_limit setting cannot be changed from the MySQL command line; it needs to be done in the configuration file and then MySQL restarted. Add the following line to the your my.cnf file:
Then restart MySQL.
In my case, it wouldn't shut down so after about 30 minutes I rebooted the server (it was reporting issues with open files again). When it came back up, the problem was gone, so increasing the open files limit solved my problem.
This is the error message in the log file when I was attempting to shut down MySQL, which confirms it was an issue with the file limit:
Grepping the error log now, I can see this particular message came up a number of times in the three hours the issue occurred for.
You can't set the open_files_limit dynamically
Note that you can't set open_files_limit dynamically from the MySQL command line; you have to change it in the configuration and restart.
If you run this:
You will get this error message:
0 comments:
Post a Comment