mysql5.5 master-slave(Replication)主從設置裝備擺設。本站提示廣大學習愛好者:(mysql5.5 master-slave(Replication)主從設置裝備擺設)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql5.5 master-slave(Replication)主從設置裝備擺設正文
一主一從:
Master:
OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.2
Slave:
OS:centos release 5.6 DB:mysql 5.5.8 IP:192.168.1.3
修正主機Master設置裝備擺設文件 (/etc/my.cnf)
[mysqld]
//至多要有server-id、與log-bin兩項
server-id=1
log-bin=/var/lib/mysql/mysql-bin
datadir=/var/lib/mysql
//為了應用事務的InnoDB在復制中最年夜的耐久性和分歧性,你應當指定innodb_flush_log_at_trx_commit=1,sync_binlog=1選項
innodb_flush_log_at_trx_commit=1
sync_binlog=1
在主機Master創立一個有復制權限的用戶
mysql>create user
[email protected];
mysql>grant replication slave on *.* to
[email protected] identified by '123456';
鎖住主機,記載二進制日記的地位(前面設置從機的時刻會用到)
mysql>flush tables with read lock;
mysal>show master status;
File:mysql-bin.000013 Position:7863951
復制主機數據庫(test)到從機
shell>/usr/bin/mysqldump test -uroot -padmin --opt | mysql test -uroot -padmin -h 192.168.1.3
從新翻開主機Master寫操作功效
mysql>unlock tables;
修正從機Slave設置裝備擺設文件(/etc/my.cnf)
[mysqld]
server-id=2 //必需是1到2的32次方之間的一個整數,且必需和主機Master的server-id紛歧樣
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
replicate-do-db=test //指定復制數據庫
datadir=/var/lib/mysql
從機Slave初始化復制
mysql>slave stop;
mysql>change master to master_host='192.168.1.2',
->master_user='repl_user',
->master_password='123456',
->master_log_file='mysql-bin.000013',
->master_log_pos=7863951;
開啟復制
mysql>start slave;
檢查復制狀況
mysql>show slave status\G
測試復制:
在主機master中對test數據庫停止sql操作,再檢查從機test數據庫能否發生同步。