15-09-2021

This commit is contained in:
2021-09-15 11:43:35 +02:00
parent bb890cba15
commit 6c514dbbef
28 changed files with 1960 additions and 770 deletions

179
docs/MySQL/repair.md Normal file
View File

@@ -0,0 +1,179 @@
# Réparer des tables :
[MySQL Server logs](https://dev.mysql.com/doc/refman/5.7/en/server-logs.html)
La 1ere chose à faire en cas de problèmes est de consulter les fichiers logs. Ceux-çi sont généralement avec les tables:
```bash
#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
```
<u>Pour réparer, 2 solutions:</u>
**1) REPAIR TABLE:**
- ne nécessite pas larrêt de MySQL
- uniquement base MyISAM
```bash
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 lerreur persiste, **vider le cache** (Flush all cache)
**2) mysqlcheck -r:**
- nécessite un arrêt du service MySQL
- uniquement base MyISAM
[MyISAM](https://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html):
```bash
$ mysqlcheck -u root -ppassword -r zenphoto .comments
zenphoto..comments OK
```
[InnoDB](https://dev.mysql.com/doc/refman/5.5/en/innodb-storage-engine.html):
```bash
$ 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](https://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html):
1) Arrêter **mysqld**:
2) Sauvegarder **mysql**:
```bash
#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**:
```mysql
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:
```bash
$ 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*:
```bash
#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:
```bash
$ 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:
```bash
$ mysqlcheck -u root -p -A --auto-repair
Enter password:
funnymac.download OK
funnymac.downloads OK
…/…
```