Drupal database issues -- anonymous comments not visible
My hosting company, Sibername, had an issue with a failing hard drive. Last night, I was unable to log into this site without hearing back from them. I was just left hanging. Turned out that the sessions table in MySQL was corrupted.
This morning, logging in worked again without having done anything differently here on my end. But now I noticed that none of the anonymous comments were showing. The comments were still present in the comments table, they were just not showing up. Comments by authenticated users were visible.
As it turned out, the users table was missing the user with UID 0 (anonymous).
The problem is that the UID column is auto incremental. The first user with UID = 0 is created during the Drupal installation process. Attempting to add any user manually will just get the next UID value. (Not the first available UID, but the highest value + 1.)
Part of the users table:
| Column | Type | Collation | Attributes | Null | Default | Extra |
|---|---|---|---|---|---|---|
| uid | int(10) | UNSIGNED | Unassigned | No | None | AUTO_INCREMENT |
I placed a query in a text file (e.g. user_0.sql and from phpMyAdmin I used the import function to merge that into the existing database. The values for the anonymous user as created by Drupal the the time of installation are as follows:
name = ''
pass = ''
mail = ''
mode = 0
sort = 0
threshold = 0
theme = ''
signature = ''
created = 0
access = 0
login = 0
status = 0
timezone = NULL
language = ''
picture = ''
init = ''
data = NULL
signature_format = 5
The MySQL query (saved in the *.sql file) looks like this:
VALUES (0, '', '', '', 0, 0, 0, '', '', 0, 0, 0, 0, NULL, '', '', '', NULL, 5);
We are instructing SQL to insert a new row into the users table with the values as Drupal creates it.
Now that this query exists in a file we can use the import function in phpMyAdmin:
Then select the file and execute the import:
That worked.
Now, it begs the question: WHY this happened? Well, my hosting company thought for some reason that this user was created by a hacker. Or so they said. It is just too silly for words.
It is definitely not normal to see that user ID removed from the users table.