MySQL master-slave configuration - ttlsa MySQL Tutorial Series

Description MySQL master network environment specifications from the configuration system: CentOS-x86_64 6.0-IP master: 192.168.50.183 IP from: 192.168.50.184 MySQL MySQL Installation Installation Configuration side skip .... main server configuration (1) open binlog # cat /etc/my.cnf | grep log-bin log-bin = mysql-bin (2) on the primary server, from the account set up a database using REPLICATION SLAVE grant privileges, such as: mysql> GRANT REPLICATION SLAVE oN *. * TO 'slave'@'192.168.50.%' IDENTIFIED BY '123456'; (3), and the backup data recording pos offset mysql> flush tables with read lock; mysqldump --all-databases> / tmp / db. sql mysql> show master status; // Check master data, you need to open binlog + ------------------ + ---------- + --- ----------- + ------------------ + | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | + --------- + --------- + ---------- + -------------- -------------- ---- + | mysql-bin.000010 | 366 | | | + ------------------ + ---------- + --- ----------- + ------------------ + 1 row in set (0.00 sec) mysql> unlock tables; Query OK, 0 rows affected (0.00 sec) configuration from the server (1) SQL # scp 192.168.50.182:/tmp/db.sql / tmp / # preparation database # mysql -uroot -p123456 </tmp/db.sql # copy back from the main server db.sql (2) modified from the server-id # cat /etc/my.cnf | grep server-id server-id = 30 # can be different from the main, if there are a plurality of slave, or other service can not be from the same # mysqld restart (3) open slave mysql> CHANGE MASTER TO MASTER_HOST = '192.168.50.182', MASTER_USER = 'slave', MASTER_PASSWORD = '123456', MASTER_LOG_FILE = 'mysql-bin.000010', MASTER_LOG_POS = 366; mysql> slave start ; // Create from the test master enable SLAVE --- master table mysql> use test sync (1); mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) Display - - from the mysql> use test; Database changed mysql> show tables; + ---------------- + | Tables_in_test | + -------------- - + | a | + ---------------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a "/tmp/db.sql / tmp / # preparation database # mysql -uroot -p123456 </tmp/db.sql # copy back from the main server db.sql (2) modified from the server-id # cat / etc / my .cnf | grep server-id server-id = 30 # can be different from the main, if there are a plurality of slave, nor the other (3) opened from the same slave mysql # service mysqld restart> CHANGE mASTER tO MASTER_HOST = '192.168. 50.182 ', MASTER_USER =' slave ', MASTER_PASSWORD =' 123456 ', MASTER_LOG_FILE =' mysql-bin.000010 ', MASTER_LOG_POS = 366; mysql> slave start; // Create from the test master enable SLAVE synchronization (1) table --- main mysql> use test; mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) Display --- from mysql> use test; Database changed mysql> show tables; + - -------------- + | Tables_in_test | + ---------------- + | a | + ---------- ------ + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"/tmp/db.sql / tmp / # preparation database # mysql -uroot -p123456 </tmp/db.sql # copy back from the main server db.sql (2) modified from the server-id # cat / etc / my .cnf | grep server-id server-id = 30 # can be different from the main, if there are a plurality of slave, nor the other (3) opened from the same slave mysql # service mysqld restart> CHANGE mASTER tO MASTER_HOST = '192.168. 50.182 ', MASTER_USER =' slave ', MASTER_PASSWORD =' 123456 ', MASTER_LOG_FILE =' mysql-bin.000010 ', MASTER_LOG_POS = 366; mysql> slave start; // Create from the test master enable SLAVE synchronization (1) table --- main mysql> use test; mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) Display --- from mysql> use test; Database changed mysql> show tables; + - -------------- + | Tables_in_test | + ---------------- + | a | + ---------- ------ + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"sql (2) modified from the server-id # cat /etc/my.cnf | grep server-id server-id = 30 # can be different from the main, if there are a plurality of slave, the other can not restart from the same # service mysqld (3) open slave mysql> CHANGE MASTER TO MASTER_HOST = '192.168.50.182', MASTER_USER = 'slave', MASTER_PASSWORD = '123456', MASTER_LOG_FILE = 'mysql-bin.000010', MASTER_LOG_POS = 366; mysql> slave start; / / SLAVE test master enable creating a table from the master --- mysql> use test sync (1); mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) from the Display --- mysql> use test; Database changed mysql> show tables; + ---------------- + | Tables_in_test | + ---------------- + | a | + ---------------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"sql (2) modified from the server-id # cat /etc/my.cnf | grep server-id server-id = 30 # can be different from the main, if there are a plurality of slave, the other can not restart from the same # service mysqld (3) open slave mysql> CHANGE MASTER TO MASTER_HOST = '192.168.50.182', MASTER_USER = 'slave', MASTER_PASSWORD = '123456', MASTER_LOG_FILE = 'mysql-bin.000010', MASTER_LOG_POS = 366; mysql> slave start; / / SLAVE test master enable creating a table from the master --- mysql> use test sync (1); mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) from the Display --- mysql> use test; Database changed mysql> show tables; + ---------------- + | Tables_in_test | + ---------------- + | a | + ---------------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"168.50.182 ', MASTER_USER =' slave ', MASTER_PASSWORD =' 123456 ', MASTER_LOG_FILE =' mysql-bin.000010 ', MASTER_LOG_POS = 366; mysql> slave start; // enable SLAVE test master-slave synchronization (1) Create a table - - main mysql> use test; mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) Display --- from mysql> use test; Database changed mysql> show tables; + ---------------- + | Tables_in_test | + ---------------- + | a | + -------- -------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"168.50.182 ', MASTER_USER =' slave ', MASTER_PASSWORD =' 123456 ', MASTER_LOG_FILE =' mysql-bin.000010 ', MASTER_LOG_POS = 366; mysql> slave start; // enable SLAVE test master-slave synchronization (1) Create a table - - main mysql> use test; mysql> create table a (i int); Query OK, 0 rows affected (0.06 sec) (2) Display --- from mysql> use test; Database changed mysql> show tables; + ---------------- + | Tables_in_test | + ---------------- + | a | + -------- -------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"+ ---------------- + | Tables_in_test | + ---------------- + | a | + ------- --------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"+ ---------------- + | Tables_in_test | + ---------------- + | a | + ------- --------- + 1 row in set (0.00 sec) can be seen in the library have been created on the master database library "a"

Reproduced in: https: //my.oschina.net/766/blog/211156

Guess you like

Origin blog.csdn.net/weixin_34206899/article/details/91493013