SQL Error : 1016 phpbb_sessions.MYD – Simple Fix Solution

Simple fix for SQL Error : 1016
This was a simple problem that came up with one of my databases, and I wasted a lot of time going the long way around the mountain. I’m posting the database problem here along with a quick fix for those with a similar error.

THE ERROR:

phpBB : Critical Error

Error creating new session

DEBUG MODE

SQL Error : 1016 Can’t open file: ‘phpbb_sessions.MYD’. (errno: 145)

INSERT INTO phpbb_sessions (session_id, session_user_id, session_start, session_time, session_ip, session_page, session_logged_in, session_admin) VALUES (‘1c2d81c6031571e71b2909fa76261504′, 2, 1161053838, 1161053838, ’47e750bd’, 0, 1, 0)

Line : 245
File : sessions.php

***********

THE FIX:

Perform the following SQL query:

REPAIR TABLE phpbb_sessions

***********************

DETAILS:

This problem can happen to many different mysql database tables and seems to happen specifically on sessions.php – My SQL had been restarted, so that might have been a cause. If you are using PHPMYADMIN to run your databases, you will not be allow to fix the database from within the tables view for that database (like you normally would). Because phpmyadmin cannot complete the listing of tables, you cannot select the table to fix, and also do not have the normal listing of functions to select from (including the “optimize” table and “repair” table functions).

But just because you can’t see the sessions or users table, doesn’t mean they don’t exist. On my databases I entered “REPAIR TABLE phpbb_sessions” as an sql query and it fixed the table, which fixed the database problem.

In looking for a fix for the problem, I saw this same error across many different software platforms including phpbb, vbulletin and several ecommerce software platforms.

My initial fix was to backup databases from the command line on the server, since I had root access. I then deleted the existing database and reloaded the backups. A very long process when the mysql query fixed it. To perform the simple query you do not need root server access, only access to phpmyadmin.
Another reason I’m posting this, is I saw several dozen instances where other people had this error for over a month, effectively closing their websites. Hopefully this will help those who, like myself, are technically challenged with mysql.

Hope that helps!

************

Another version of a related error:

phpBB : Critical Error

Error doing DB query userdata row fetch

DEBUG MODE

SQL Error : 1146 Table ‘databasename.phpbb_users’ doesn’t exist

SELECT u.* FROM phpbb_users u, phpbb_sessions_keys k WHERE u.user_id = 2 AND u.user_active = 1 AND k.user_id = u.user_id AND k.key_id = ‘d0d838d45d9db9fea44a2500bb8199ab’

Line : 89
File : sessions.php