Mysql
(→MYSQL) |
|||
| Ligne 32 : | Ligne 32 : | ||
-E => presentation à la vertical plutôt qu'a l'horizontal | -E => presentation à la vertical plutôt qu'a l'horizontal | ||
--socket => permet de prendre un autre service que celui par defaut | --socket => permet de prendre un autre service que celui par defaut | ||
| + | |||
| + | |||
| + | ------ | ||
| + | |||
| + | == replication == | ||
| + | |||
| + | la doc sur le site de mysql => [http://dev.mysql.com/doc/refman/5.0/fr/replication-howto.html] | ||
| + | |||
| + | On lock les tables en écriture | ||
| + | mysql> FLUSH TABLES WITH READ LOCK; | ||
| + | |||
| + | On lance le dump de toutes les données. | ||
| + | mysqldump -u USER -p****** -A > /PATH/TO/DUMPFILE | ||
| + | |||
| + | On récupère la position du master | ||
| + | mysql> SHOW MASTER STATUS; | ||
| + | *************************** 1. row *************************** | ||
| + | File: ns20587.000012 | ||
| + | Position: 8330324 | ||
| + | Binlog_Do_DB: | ||
| + | Binlog_Ignore_DB: | ||
| + | 1 row in set (0.00 sec) | ||
| + | |||
| + | autre présentations en fonction de la façon de se loguer ( -E ) | ||
| + | mysql> SHOW MASTER STATUS; | ||
| + | +----------------+----------+--------------+------------------+ | ||
| + | | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | | ||
| + | +----------------+----------+--------------+------------------+ | ||
| + | | ns20587.000012 | 8707042 | | | | ||
| + | +----------------+----------+--------------+------------------+ | ||
| + | |||
| + | |||
| + | On unlock les tables | ||
| + | mysql> UNLOCK TABLES; | ||
| + | |||
| + | On restaure les données sur le slave après les y avoir transféré. | ||
| + | mysql -u USER -p******** < /PATH/TO/DUMPFILE | ||
| + | |||
| + | On donne les au slave les instructions pour qu'il aille chercher sur le master les infos dans les fichiers bin. | ||
| + | mysql> CHANGE MASTER TO MASTER_HOST='HOSTNAME', MASTER_USER='USER', MASTER_PASSWORD='********', MASTER_LOG_FILE='FILE', MASTER_LOG_POS=POSITION; | ||
| + | |||
| + | On peu ensuite vérifier que le slave se synchronise bien (l'autre vue sans le -E est illisible pour moi ...) | ||
| + | mysql> show slave status; | ||
| + | *************************** 1. row *************************** | ||
| + | Slave_IO_State: Waiting for master to send event | ||
| + | Master_Host: vpn.talevas.com | ||
| + | Master_User: root | ||
| + | Master_Port: 3306 | ||
| + | Connect_Retry: 60 | ||
| + | Master_Log_File: ns20587.000012 | ||
| + | Read_Master_Log_Pos: 8726915 | ||
| + | Relay_Log_File: mysqld-relay-bin.000008 | ||
| + | Relay_Log_Pos: 1508334 | ||
| + | Relay_Master_Log_File: ns20587.000012 | ||
| + | Slave_IO_Running: Yes | ||
| + | Slave_SQL_Running: Yes | ||
| + | Replicate_Do_DB: | ||
| + | Replicate_Ignore_DB: | ||
| + | Replicate_Do_Table: | ||
| + | Replicate_Ignore_Table: | ||
| + | Replicate_Wild_Do_Table: | ||
| + | Replicate_Wild_Ignore_Table: | ||
| + | Last_Errno: 0 | ||
| + | Last_Error: | ||
| + | Skip_Counter: 0 | ||
| + | Exec_Master_Log_Pos: 8726915 | ||
| + | Relay_Log_Space: 1508334 | ||
| + | Until_Condition: None | ||
| + | Until_Log_File: | ||
| + | Until_Log_Pos: 0 | ||
| + | Master_SSL_Allowed: No | ||
| + | Master_SSL_CA_File: | ||
| + | Master_SSL_CA_Path: | ||
| + | Master_SSL_Cert: | ||
| + | Master_SSL_Cipher: | ||
| + | Master_SSL_Key: | ||
| + | Seconds_Behind_Master: 0 | ||
| + | |||
| + | mysql> show slave status; | ||
| + | +----------------------------------+-----------------+-------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ | ||
| + | | Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | | ||
| + | +----------------------------------+-----------------+-------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ | ||
| + | | Waiting for master to send event | vpn.talevas.com | root | 3306 | 60 | ns20587.000012 | 8736018 | mysqld-relay-bin.000008 | 1517437 | ns20587.000012 | Yes | Yes | | | | | | | 0 | | 0 | 8736018 | 1517437 | None | | 0 | No | | | | | | 0 | | ||
| + | +----------------------------------+-----------------+-------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ | ||
Version du 22 février 2008 à 16:38
MYSQL
désactiver les logs binaires qui prennent plein de place pour rien sur une machine en prod.
vim /etc/mysql/my.cnf
commenter la ligne log-bin et la suivante.
Déplacer le répertoire de stockage des bases de données.
cp -rp /var/lib/mysql /home (par exemple) vim /etc/mysql/my.cnf
modifier la ligne "datadir"
#datadir = /var/lib/mysql datadir = /home/mysql
mysqladmin -u root flush-privileges password ******** --socket=/var/run/mysqld/mysqld-ns37682.sock
connection en local
mysql -u root -p******* -E --socket=/var/run/mysqld/mysqld-ns37682.sock user password -E => presentation à la vertical plutôt qu'a l'horizontal --socket => permet de prendre un autre service que celui par defaut
replication
la doc sur le site de mysql => [1]
On lock les tables en écriture
mysql> FLUSH TABLES WITH READ LOCK;
On lance le dump de toutes les données.
mysqldump -u USER -p****** -A > /PATH/TO/DUMPFILE
On récupère la position du master
mysql> SHOW MASTER STATUS;
*************************** 1. row ***************************
File: ns20587.000012
Position: 8330324
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
autre présentations en fonction de la façon de se loguer ( -E )
mysql> SHOW MASTER STATUS; +----------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +----------------+----------+--------------+------------------+ | ns20587.000012 | 8707042 | | | +----------------+----------+--------------+------------------+
On unlock les tables
mysql> UNLOCK TABLES;
On restaure les données sur le slave après les y avoir transféré.
mysql -u USER -p******** < /PATH/TO/DUMPFILE
On donne les au slave les instructions pour qu'il aille chercher sur le master les infos dans les fichiers bin.
mysql> CHANGE MASTER TO MASTER_HOST='HOSTNAME', MASTER_USER='USER', MASTER_PASSWORD='********', MASTER_LOG_FILE='FILE', MASTER_LOG_POS=POSITION;
On peu ensuite vérifier que le slave se synchronise bien (l'autre vue sans le -E est illisible pour moi ...)
mysql> show slave status;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: vpn.talevas.com
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: ns20587.000012
Read_Master_Log_Pos: 8726915
Relay_Log_File: mysqld-relay-bin.000008
Relay_Log_Pos: 1508334
Relay_Master_Log_File: ns20587.000012
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 8726915
Relay_Log_Space: 1508334
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
mysql> show slave status; +----------------------------------+-----------------+-------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ | Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | +----------------------------------+-----------------+-------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Waiting for master to send event | vpn.talevas.com | root | 3306 | 60 | ns20587.000012 | 8736018 | mysqld-relay-bin.000008 | 1517437 | ns20587.000012 | Yes | Yes | | | | | | | 0 | | 0 | 8736018 | 1517437 | None | | 0 | No | | | | | | 0 |
+----------------------------------+-----------------+-------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+