Este problema sucede porque la base de datos de MySQL esta corrupta, ya sea por un problema en el disco, al matar el proceso de MySQL/MariaDB sin pararlo antes o similares.
shell> mysql
MariaDB> SELECT * FROM mysql.user;
ERROR 1194 (HY000): Table 'user' is marked as crashed and should be repaired
Warning in .\libraries\classes\Dbal\DbiMysqli.php#240
mysqli::query(): (HY000/126): Index for table '.\mysql\user.MYI' is corrupt; try to repair it
Para solucionar esto hacemos lo siguiente:
1. Comprobar el estado de la DB:
En este caso se ve que mi tabla esta corrupta. "Corrupt"
shell> mysql -u root -p
MariaDB [(none)]> CHECK TABLE mysql.user;
+------------+-------+----------+-----------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------+-------+----------+-----------------------------------------------------------------+
| mysql.user | check | warning | Size of indexfile is: 5628 Should be: 4096 |
| mysql.user | check | warning | Size of datafile is: 5012 Should be: 244 |
| mysql.user | check | error | Can't read indexpage from filepos: 2048 |
| mysql.user | check | Error | Index for table '.\mysql\user.MYI' is corrupt; try to repair it |
| mysql.user | check | error | Corrupt |
+------------+-------+----------+-----------------------------------------------------------------+
5 rows in set (0.00 sec)
2. Reparar la base de datos: Mysql.User
MariaDB [(none)]> REPAIR TABLE mysql.user;
+------------+--------+----------+--------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+------------+--------+----------+--------------------------------------------------+
| mysql.user | repair | info | Wrong bytesec: 50- 48- 50 at 0; Skipped |
| mysql.user | repair | info | Found block that points outside data file at 92 |
| mysql.user | repair | info | Found block that points outside data file at 96 |
| mysql.user | repair | info | Found block that points outside data file at 100 |
| mysql.user | repair | info | Found block that points outside data file at 104 |
| mysql.user | repair | info | Found block that points outside data file at 108 |
| mysql.user | repair | info | Found block that points outside data file at 112 |
| mysql.user | repair | info | Wrong bytesec: 50- 48- 50 at 244; Skipped |
| mysql.user | repair | warning | Number of rows changed from 4 to 2 |
| mysql.user | repair | status | OK |
+------------+--------+----------+--------------------------------------------------+
10 rows in set (0.00 sec)
3. Volvemos a comprobar el estado de la base de datos:
MariaDB [(none)]> CHECK TABLE mysql.user;
+------------+-------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+------------+-------+----------+----------+
| mysql.user | check | status | OK |
+------------+-------+----------+----------+
1 row in set (0.00 sec)
4. Reiniciamos el servicio de MySQL / MariaDB
Después de reiniciar el servidor ya debería de desaparecer este problema.
Nota: En algunos casos debemos hacer los mismos pasos para la base de datos principal de MySQL:
shell> mysql -u root -p
MariaDB [(none)]> CHECK TABLE mysql.db;
MariaDB [(none)]> REPAIR TABLE mysql.db;
MariaDB [(none)]> CHECK TABLE mysql.db;