Aller au contenu

Réparer des tables :

MySQL Server logs

La 1ere chose à faire en cas de problèmes est de consulter les fichiers logs. Ceux-çi sont généralement avec les tables:

#osx (Homebrew):

$ cd /usr/local/var/mysql
total 388560
drwxr-xr-x  32 bruno  admin      1024 28 nov 16:53 .
drwxrwxr-x  13 bruno  admin       416 16 fév  2018 ..
-rw-rw----   1 bruno  admin     16384 28 nov 08:08 aria_log.00000001
-rw-rw----   1 bruno  admin        52 28 nov 08:08 aria_log_control
drwx------  48 bruno  admin      1536  1 déc 17:05 funnymac
drwx------  53 bruno  admin      1696  1 déc 17:05 ghost_prod
-rw-r-----   1 bruno  admin     15114 28 nov 08:08 ib_buffer_pool
-rw-rw----   1 bruno  admin  50331648  3 déc 07:19 ib_logfile0
-rw-rw----   1 bruno  admin  50331648 24 oct 12:51 ib_logfile1
-rw-rw----   1 bruno  admin  79691776  3 déc 07:19 ibdata1
-rw-rw----   1 bruno  admin  12582912 28 nov 16:53 ibtmp1
drwx------   9 bruno  admin       288  1 déc 17:05 mgpt
-rw-rw----   1 bruno  admin         0 24 jul  2017 multi-master.info
drwx------  89 bruno  admin      2848  1 déc 17:05 mysql
drwx------   3 bruno  admin        96 24 jul  2017 performance_schema
drwx------  41 bruno  admin      1312  1 déc 17:05 phpmyadmi
-rw-rw----   1 bruno  admin   1271878  3 déc 07:19 silverbook.home.err
-rw-rw----   1 bruno  admin         5 28 nov 16:53 silverbook.home.pid

Pour réparer, 2 solutions:

1) REPAIR TABLE:

  • ne nécessite pas l’arrêt de MySQL
  • uniquement base MyISAM
MariaDB [zenphoto]> REPAIR TABLE _tags;
+----------------+--------+----------+---------------------------------------------------------+
| Table          | Op     | Msg_type | Msg_text                                                |
+----------------+--------+----------+---------------------------------------------------------+
| zenphoto._tags | repair | note     | The storage engine for the table doesn't support repair |
+----------------+--------+----------+---------------------------------------------------------+

1 row in set (0.006 sec)

Si l’erreur persiste, vider le cache (Flush all cache)

2) mysqlcheck -r:

  • nécessite un arrêt du service MySQL

  • uniquement base MyISAM

MyISAM:

$ mysqlcheck -u root -ppassword -r zenphoto .comments

zenphoto..comments                                 OK

InnoDB:

$ mysqlcheck -u root -ppassword -r zenphoto _tags

zenphoto._tags

note     : The storage engine for the table doesn't support repair

Pour les tables InnoDB, il faut forcer la récupération:

1) Arrêter **mysqld**:

2) Sauvegarder **mysql**:
#Linux
/var/lib/mysql/

#osx (Homebrew)
/usr/local/var/mysql/
3) Ajouter au fichier de configuration MySQL my.cnf:
#osx (Homebrew): /usr/local/etc/my.cnf

[mysqld]
innodb_force_recovery = 4
4) Redémarrer **mysqld**:

5a) Faire un dump des tables de la base avec SELECT ... INTO OUTFILE:

MariaDB [zenphoto]> SELECT * FROM _tags INTO OUTFILE '/tmp/corrupted.txt';
Query OK, 170 rows affected (0.011 sec)

# Pour exporter au format csv:
MariaDB [zenphoto]> SELECT * FROM _tags INTO OUTFILE '/tmp/corrupted.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
Query OK, 170 rows affected (0.006 sec)

5b) Faire. un dump de toutes les tables:

$ mysqldump -A -u root -ppassword > '/tmp/dump.sql';
6) Parfois cela peut suffire. Sinon,

7) Supprimer les tables / bases corrompues (DROP ...)

8) Arrêter **mysqld**:

9) Supprimer les ib*:
#Linux
/var/lib/mysql/ib*

#osx (Homebrew)
/usr/local/var/mysql/ib*
10) Quitter le mode force recovery:
[mysqld]
#innodb_force_recovery = 0
11) Redémarrer **mysqld**:

12) Restaurer les bases:
$ mysql -u root -ppassword < dump.sql

https://www.nixpal.com/mysql-innodb-corruption-repair-guide/

Vérifier et réparer:

Vérifier toutes les bases et réparer les tables corrompues:

$ mysqlcheck -u root -p -A --auto-repair

Enter password:

funnymac.download                                  OK
funnymac.downloads                                 OK
…/…

Dernière mise à jour: March 4, 2022