User Tools

Site Tools


doc:appunti:linux:sa:mysql_replica_master_master

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
doc:appunti:linux:sa:mysql_replica_master_master [2011/09/08 12:48] – created niccolodoc:appunti:linux:sa:mysql_replica_master_master [2019/09/30 09:51] (current) – [Configurare la replica master-master] niccolo
Line 1: Line 1:
 ====== MySQL replica master-master ====== ====== MySQL replica master-master ======
  
 +Riferimenti web:
 +
 +  * **[[http://www.howtoforge.com/mysql5_master_master_replication_debian_etch| Up Master-Master Replication With MySQL 5 On Debian Etch]]**
 +  * **[[http://www.howtoforge.com/mysql_master_master_replication|MySQL Master Master Replication]]**
 +
 +===== Configurare la replica master-master =====
 +
 +Con questa configurazione si tiene replicato **un solo database**.
 +
 +<code>
 +-- Su server1
 +GRANT REPLICATION SLAVE ON *.* TO 'slave2_user'@'%' IDENTIFIED BY 'slave2_password';
 +FLUSH PRIVILEGES;
 +
 +CREATE DATABASE exampledb;
 +CONNECT exampledb;
 +
 +CREATE TABLE clienti (
 +    id INTEGER NOT NULL AUTO_INCREMENT,
 +    name CHAR(100),
 +    PRIMARY KEY (id)
 +) ENGINE=INNODB;
 +
 +CREATE TABLE fatture (
 +    id INTEGER NOT NULL AUTO_INCREMENT,
 +    cliente_id INTEGER,
 +    PRIMARY KEY (id),
 +    FOREIGN KEY (cliente_id) REFERENCES clienti(id)
 +) ENGINE=INNODB;
 +
 +SHOW TABLE STATUS;
 +
 +INSERT INTO clienti (name) VALUES ('Rigacci.Org');
 +INSERT INTO fatture (cliente_id) VALUES (1);
 +DELETE FROM clienti;
 +
 +vi /etc/mysql/my.cnf
 +# Vedere la man page di my.cnf, che non esiste.
 +/etc/init.d/mysql restart
 +
 +-- Su server2
 +GRANT REPLICATION SLAVE ON *.* TO 'slave1_user'@'%' IDENTIFIED BY 'slave1_password';
 +FLUSH PRIVILEGES;
 +
 +vi /etc/mysql/my.cnf
 +# Vedere la man page di my.cnf, che non esiste.
 +/etc/init.d/mysql restart
 +</code>
 +
 +Per vedere se si sono assegnati i permessi di replica:
 +
 +<code>
 +SHOW GRANTS FOR 'slave2_user'@'%';
 +</code>
 +
 +Ovviamente è opportuno concedere i grant non dall'indirizzo IP wildcard **%%%%%**, ma al singolo utente/indirizzo, del tipo **%%'replication'@'116.213.177.13'%%**.
 +===== Sincronizzare il db =====
 +
 +<code>
 +-- Su server1
 +USE exampledb;
 +FLUSH TABLES WITH READ LOCK;
 +SHOW MASTER STATUS;
 +-- Prendere nota dello status.
 +-- Fare un dump e copiarlo sull'altro host.
 +UNLOCK TABLES;
 +
 +-- Su server2
 +-- mysqladmin --user=root --password stop-slave
 +CREATE DATABASE exampledb;
 +-- mysql -u root -p exampledb < exampledb.sql
 +USE exampledb;
 +FLUSH TABLES WITH READ LOCK;
 +SHOW MASTER STATUS;
 +-- Prendere nota dello status.
 +UNLOCK TABLES;
 +CHANGE MASTER TO MASTER_HOST='192.168.3.71', MASTER_USER='slave2_user',
 +    MASTER_PASSWORD='slave2_password', MASTER_LOG_FILE='mysql-bin.000001',
 +    MASTER_LOG_POS=106;
 +START SLAVE;
 +SHOW SLAVE STATUS;
 +
 +-- Su server1
 +STOP SLAVE;
 +CHANGE MASTER TO MASTER_HOST='192.168.3.73', MASTER_USER='slave1_user',
 +    MASTER_PASSWORD='slave1_password', MASTER_LOG_FILE='mysql-bin.000001',
 +    MASTER_LOG_POS=2359;
 +START SLAVE;
 +SHOW SLAVE STATUS;
 +</code>
 ===== Crash test ===== ===== Crash test =====
  
doc/appunti/linux/sa/mysql_replica_master_master.1315478898.txt.gz · Last modified: 2011/09/08 12:48 by niccolo