Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| elearning:workbooks:mysql:my05 [2020/02/21 08:34] – admin | elearning:workbooks:mysql:my05 [2022/11/08 15:17] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 98: | Ligne 98: | ||
| # mysql –u –root –p –default_character_set=latin1 dbname < backup.sql [Entrée] | # mysql –u –root –p –default_character_set=latin1 dbname < backup.sql [Entrée] | ||
| + | | ||
| + | ====Mariabackup==== | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# curl -sS https:// | ||
| + | [info] Checking for script prerequisites. | ||
| + | [info] Repository file successfully written to / | ||
| + | [info] Adding trusted package signing keys... | ||
| + | / | ||
| + | ~ | ||
| + | [info] Successfully added trusted package signing keys | ||
| + | [info] Cleaning package cache... | ||
| + | Loaded plugins: fastestmirror, | ||
| + | Cleaning repos: base extras mariadb-main mariadb-maxscale mariadb-tools updates | ||
| + | Cleaning up list of fastest mirrors | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# yum install MariaDB-backup | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# wget http:// | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# tar xvf sakila-db.tar.gz | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# mysql -uroot -p < sakila-db/ | ||
| + | Enter password: | ||
| + | [root@centos7 ~]# mysql -uroot -p < sakila-db/ | ||
| + | Enter password: | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# mkdir / | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# mariabackup --backup --target-dir=/ | ||
| + | ..... | ||
| + | [00] 2021-11-03 16:28:35 >> log scanned up to (5455954) | ||
| + | [00] 2021-11-03 16:28:35 Executing BACKUP STAGE END | ||
| + | [00] 2021-11-03 16:28:35 All tables unlocked | ||
| + | [00] 2021-11-03 16:28:35 Copying ib_buffer_pool to / | ||
| + | [00] 2021-11-03 16: | ||
| + | [00] 2021-11-03 16:28:35 Backup created in directory '/ | ||
| + | [00] 2021-11-03 16:28:35 Writing backup-my.cnf | ||
| + | [00] 2021-11-03 16: | ||
| + | [00] 2021-11-03 16:28:35 Writing xtrabackup_info | ||
| + | [00] 2021-11-03 16: | ||
| + | [00] 2021-11-03 16:28:35 Redo log (from LSN 42161 to 5455954) was copied. | ||
| + | [00] 2021-11-03 16:28:35 completed OK! | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# ls -l / | ||
| + | total 18040 | ||
| + | -rw-r-----. 1 root root | ||
| + | -rw-r-----. 1 root root 52 Nov 3 16:28 aria_log_control | ||
| + | -rw-r-----. 1 root root 297 Nov 3 16:28 backup-my.cnf | ||
| + | -rw-r-----. 1 root root 942 Nov 3 16:28 ib_buffer_pool | ||
| + | -rw-r-----. 1 root root 12582912 Nov 3 16:28 ibdata1 | ||
| + | -rw-r-----. 1 root root 5416448 Nov 3 16:28 ib_logfile0 | ||
| + | drwx------. 2 root root 4096 Nov 3 16:28 mysql | ||
| + | drwx------. 2 root root 19 Nov 3 16:28 performance_schema | ||
| + | drwx------. 2 root root 4096 Nov 3 16:28 sakila | ||
| + | drwx------. 2 root root 8192 Nov 3 16:28 sys | ||
| + | drwx------. 2 root root 19 Nov 3 16:28 test | ||
| + | -rw-r-----. 1 root root 75 Nov 3 16:28 xtrabackup_checkpoints | ||
| + | -rw-r-----. 1 root root 448 Nov 3 16:28 xtrabackup_info | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# mysql -u root -p | ||
| + | Enter password: | ||
| + | Welcome to the MariaDB monitor. | ||
| + | Your MariaDB connection id is 19 | ||
| + | Server version: 10.6.4-MariaDB MariaDB Server | ||
| + | |||
| + | Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. | ||
| + | |||
| + | Type ' | ||
| + | |||
| + | MariaDB [(none)]> | ||
| + | Query OK, 1 row affected (0.001 sec) | ||
| + | |||
| + | MariaDB [(none)]> | ||
| + | Bye | ||
| + | |||
| + | [root@centos7 ~]# wget http:// | ||
| + | |||
| + | [root@centos7 ~]# gunzip world-db.tar.gz | ||
| + | |||
| + | [root@centos7 ~]# ls -l | ||
| + | total 44500 | ||
| + | -rw-------. 1 root root 1200 Apr 30 2016 anaconda-ks.cfg | ||
| + | -rw-------. 1 root root 1251 Apr 30 2016 initial-setup-ks.cfg | ||
| + | -rwxrwxrwx. 1 root root 19081806 Jan 24 2016 Remote Access-linux64-offline | ||
| + | -rw-r--r--. 1 root root 19087360 Jan 24 2016 Remote Access-linux64-offline.tar | ||
| + | -rwxrwxrwx. 1 root root 3121044 Jan 24 2016 Remote Access-linux64-online | ||
| + | -rw-r--r--. 1 root root 3123200 Jan 24 2016 Remote Access-linux64-online.tar | ||
| + | drwxr-xr-x. 2 500 500 69 Nov 1 00:05 sakila-db | ||
| + | -rw-r--r--. 1 root root | ||
| + | -rw-r--r--. 1 root root | ||
| + | |||
| + | [root@centos7 ~]# tar xvf world-db.tar | ||
| + | world-db/ | ||
| + | world-db/ | ||
| + | |||
| + | [root@centos7 ~]# mysql -uroot -p world < world-db/ | ||
| + | Enter password: | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# mariabackup --backup --target-dir=/ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | [root@centos7 ~]# cat / | ||
| + | backup_type = full-backuped | ||
| + | from_lsn = 0 | ||
| + | to_lsn = 42161 | ||
| + | last_lsn = 5455954 | ||
| + | </ | ||
| + | |||
| Ligne 176: | Ligne 304: | ||
| <WRAP center round important 60%> | <WRAP center round important 60%> | ||
| - | **Imporatnt** - Dans le cas de deux machines physiques, cette commande doit être saisie sur le maître **et** l' | + | **Important** - Dans le cas de deux machines physiques, cette commande doit être saisie sur le maître **et** l' |
| </ | </ | ||
| Ligne 204: | Ligne 332: | ||
| MariaDB [mysql]> | MariaDB [mysql]> | ||
| </ | </ | ||
| - | |||
| - | ===Création d'un clone de la VM=== | ||
| - | |||
| - | Arrêtez votre VM : | ||
| - | |||
| - | < | ||
| - | MariaDB [mysql]> exit | ||
| - | Bye | ||
| - | [root@centos7 ~]# shutdown -h now | ||
| - | </ | ||
| - | |||
| - | Créez deux clônes, **maitre** et **esclave** dans VirtualBox. | ||
| ===Configurer le maître=== | ===Configurer le maître=== | ||
| - | |||
| - | <WRAP center round todo 60%> | ||
| - | Pour chacune des VM maître et esclave, configurez l' | ||
| - | </ | ||
| - | |||
| - | Lancez la VM **maître**. | ||
| - | |||
| - | Configurez la carte réseau en adresse IP fixe : | ||
| - | |||
| - | < | ||
| - | [root@centos7 ~]# nmcli connection add con-name ip_fixe ifname enp0s3 type ethernet ip4 192.168.1.10/ | ||
| - | Connection ' | ||
| - | [root@centos7 ~]# nmcli connection up ip_fixe | ||
| - | Connection successfully activated (D-Bus active path: / | ||
| - | [root@centos7 ~]# ip addr | ||
| - | 1: lo: < | ||
| - | link/ | ||
| - | inet 127.0.0.1/8 scope host lo | ||
| - | | ||
| - | inet6 ::1/128 scope host | ||
| - | | ||
| - | 2: enp0s3: < | ||
| - | link/ether 08: | ||
| - | inet 192.168.1.10/ | ||
| - | | ||
| - | inet6 fe80:: | ||
| - | | ||
| - | </ | ||
| Ajoutez ensuite deux lignes dans la section **mysqld** du fichier **/ | Ajoutez ensuite deux lignes dans la section **mysqld** du fichier **/ | ||
| Ligne 297: | Ligne 385: | ||
| ===Configurer l' | ===Configurer l' | ||
| - | Lancez | + | Connectez-vous à la VM **esclave** |
| < | < | ||
| - | [root@centos7 ~]# nmcli connection add con-name ip_fixe ifname enp0s3 type ethernet ip4 192.168.1.11/24 gw4 10.0.2.2 | + | [root@centos7 ~]# ping -c3 10.0.2.51 |
| - | Connection ' | + | PING 10.0.2.51 (10.0.2.51) 56(84) bytes of data. |
| - | [root@centos7 ~]# nmcli connection up ip_fixe | + | 64 bytes from 10.0.2.51: icmp_seq=1 ttl=64 time=2.40 ms |
| - | Connection successfully activated (D-Bus active path: / | + | 64 bytes from 10.0.2.51: icmp_seq=2 ttl=64 time=1.52 ms |
| - | [root@centos7 ~]# ip addr | + | 64 bytes from 10.0.2.51: icmp_seq=3 ttl=64 time=1.49 ms |
| - | 1: lo: < | + | |
| - | | + | --- 10.0.2.51 ping statistics --- |
| - | inet 127.0.0.1/8 scope host lo | + | 3 packets transmitted, 3 received, 0% packet loss, time 2003ms |
| - | | + | rtt min/avg/max/mdev = 1.493/1.809/2.407/0.425 ms |
| - | inet6 ::1/128 scope host | + | |
| - | valid_lft forever preferred_lft forever | + | |
| - | 2: enp0s3: < | + | |
| - | link/ether 08: | + | |
| - | inet 192.168.1.11/24 brd 192.168.1.255 scope global enp0s3 | + | |
| - | | + | |
| - | inet6 fe80:: | + | |
| - | | + | |
| </ | </ | ||
| - | Vérifiez que vous voyez le maître | + | Installez MariaDB puis : |
| + | |||
| + | * configurez | ||
| + | * configurez les logs | ||
| + | |||
| + | La base de données du Maître doit être transférée sur l' | ||
| + | |||
| + | Contrôlez d' | ||
| < | < | ||
| - | [root@centos7 ~]# ping -c3 192.168.1.10 | + | [root@centos7 ~]# mysql -u root -p mysql |
| - | PING 192.168.1.10 (192.168.1.10) 56(84) bytes of data. | + | Enter password: |
| - | 64 bytes from 192.168.1.10: icmp_seq=1 ttl=64 time=2.40 ms | + | Reading table information for completion of table and column names |
| - | 64 bytes from 192.168.1.10: | + | You can turn off this feature to get a quicker startup with -A |
| - | 64 bytes from 192.168.1.10: | + | |
| - | --- 192.168.1.10 ping statistics | + | Welcome to the MariaDB monitor. |
| - | 3 packets transmitted, | + | Your MariaDB connection id is 2 |
| - | rtt min/avg/max/mdev = 1.493/1.809/2.407/0.425 ms | + | Server version: 5.5.56-MariaDB MariaDB Server |
| + | |||
| + | Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. | ||
| + | |||
| + | Type ' | ||
| + | |||
| + | MariaDB [mysql]> SHOW VARIABLES LIKE ' | ||
| + | +-----------------+-------+ | ||
| + | | Variable_name | ||
| + | +-----------------+-------+ | ||
| + | | max_connections | 151 | | ||
| + | +-----------------+-------+ | ||
| + | 1 row in set (0.00 sec) | ||
| + | |||
| + | MariaDB [mysql]> | ||
| + | </code> | ||
| + | |||
| + | Notez la valeur et ensuite définissez-la à 1 pour n' | ||
| + | |||
| + | < | ||
| + | MariaDB [mysql]> SET GLOBAL max_connections | ||
| + | Query OK, 0 rows affected | ||
| + | |||
| + | MariaDB [mysql]> SHOW VARIABLES LIKE ' | ||
| + | +-----------------+-------+ | ||
| + | | Variable_name | ||
| + | +-----------------+-------+ | ||
| + | | max_connections | 1 | | ||
| + | +-----------------+-------+ | ||
| + | 1 row in set (0.00 sec) | ||
| + | |||
| + | MariaDB [mysql]> | ||
| + | </code> | ||
| + | |||
| + | Pour sauvegarder la totalité des bases de données sur le maître, il convient d' | ||
| + | |||
| + | # mysqldump --user=root --password=fenestros1 --extended-insert --all-databases --master-data --event | ||
| + | |||
| + | <WRAP center round important 60%> | ||
| + | **Important** - Notez que **--master-data** permet à mysqldump de récupérer les données du maître concernant la réplication. | ||
| + | </WRAP> | ||
| + | |||
| + | Ensuite sur l' | ||
| + | |||
| + | # mysql --user=root --password=fenestros < /tmp/ | ||
| + | |||
| + | Dernièrement, | ||
| + | |||
| + | < | ||
| + | MariaDB [mysql]> SET GLOBAL max_connections = 151; | ||
| + | Query OK, 0 rows affected (0.01 sec) | ||
| + | |||
| + | MariaDB [mysql]> SHOW VARIABLES LIKE ' | ||
| + | +-----------------+-------+ | ||
| + | | Variable_name | ||
| + | +-----------------+-------+ | ||
| + | | max_connections | 151 | | ||
| + | +-----------------+-------+ | ||
| + | 1 row in set (0.37 sec) | ||
| + | |||
| + | MariaDB [mysql]> | ||
| </ | </ | ||
| Ligne 413: | Ligne 559: | ||
| Type ' | Type ' | ||
| - | MariaDB [mysql]> CHANGE MASTER TO MASTER_HOST ='192.168.1.10'; | + | MariaDB [mysql]> CHANGE MASTER TO MASTER_HOST ='10.0.2.51'; |
| Query OK, 0 rows affected (0.39 sec) | Query OK, 0 rows affected (0.39 sec) | ||
| Ligne 436: | Ligne 582: | ||
| 4 | 4 | ||
| - | 192.168.1.10 | + | 10.0.2.51 |
| replicant | replicant | ||
| password | password | ||
| Ligne 518: | Ligne 664: | ||
| | Slave_IO_State | | Slave_IO_State | ||
| +----------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+----------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+-----------------------------+------------------+ | +----------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+----------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+-----------------------------+------------------+ | ||
| - | | Connecting to master | 192.168.1.10 | replicant | + | | Connecting to master | 10.0.2.51 | replicant |
| +----------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+----------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+-----------------------------+------------------+ | +----------------------+--------------+-------------+-------------+---------------+-----------------+---------------------+----------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+----------------+----------------+-----------------------------+------------------+ | ||
| 1 row in set (0.00 sec) | 1 row in set (0.00 sec) | ||
| Ligne 620: | Ligne 766: | ||
| </ | </ | ||
| - | =====Annexe #1===== | ||
| - | Dans le cas de deux machines physiques, la base de données du Maître doit être transférer sur l' | ||
| - | Contrôlez d' | ||
| - | < | ||
| - | [root@centos7 ~]# mysql -u root -p mysql | ||
| - | Enter password: | ||
| - | Reading table information for completion of table and column names | ||
| - | You can turn off this feature to get a quicker startup with -A | ||
| - | |||
| - | Welcome to the MariaDB monitor. | ||
| - | Your MariaDB connection id is 2 | ||
| - | Server version: 5.5.56-MariaDB MariaDB Server | ||
| - | |||
| - | Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. | ||
| - | |||
| - | Type ' | ||
| - | |||
| - | MariaDB [mysql]> SHOW VARIABLES LIKE ' | ||
| - | +-----------------+-------+ | ||
| - | | Variable_name | ||
| - | +-----------------+-------+ | ||
| - | | max_connections | 151 | | ||
| - | +-----------------+-------+ | ||
| - | 1 row in set (0.00 sec) | ||
| - | |||
| - | MariaDB [mysql]> | ||
| - | </ | ||
| - | |||
| - | Notez la valeur et ensuite définissez-la à 1 pour n' | ||
| - | |||
| - | < | ||
| - | MariaDB [mysql]> SET GLOBAL max_connections = 1; | ||
| - | Query OK, 0 rows affected | ||
| - | |||
| - | MariaDB [mysql]> SHOW VARIABLES LIKE ' | ||
| - | +-----------------+-------+ | ||
| - | | Variable_name | ||
| - | +-----------------+-------+ | ||
| - | | max_connections | 1 | | ||
| - | +-----------------+-------+ | ||
| - | 1 row in set (0.00 sec) | ||
| - | |||
| - | MariaDB [mysql]> | ||
| - | </ | ||
| - | |||
| - | Pour sauvegarder la totalité des bases de données sur le maître, il convient d' | ||
| - | |||
| - | # mysqldump --user=root --password=fenestros1 --extended-insert --all-databases --master-data --event | ||
| - | |||
| - | <WRAP center round important 60%> | ||
| - | **Important** - Notez que **--master-data** permet à mysqldump de récupérer les données du maître concernant la réplication. | ||
| - | </ | ||
| - | |||
| - | Ensuite sur l' | ||
| - | |||
| - | # mysql --user=root --password=fenestros < / | ||
| - | |||
| - | Dernièrement, | ||
| - | |||
| - | < | ||
| - | MariaDB [mysql]> SET GLOBAL max_connections = 151; | ||
| - | Query OK, 0 rows affected (0.01 sec) | ||
| - | |||
| - | MariaDB [mysql]> SHOW VARIABLES LIKE ' | ||
| - | +-----------------+-------+ | ||
| - | | Variable_name | ||
| - | +-----------------+-------+ | ||
| - | | max_connections | 151 | | ||
| - | +-----------------+-------+ | ||
| - | 1 row in set (0.37 sec) | ||
| - | |||
| - | MariaDB [mysql]> | ||
| - | </ | ||
| ----- | ----- | ||
| < | < | ||
| < | < | ||
| - | Copyright © 2020 Hugh Norris. | + | Copyright © 2021 Hugh Norris. |
| </ | </ | ||
| </ | </ | ||