標籤:mysql
系統內容
系統版本:Centos6.4-x86.64
軟體環境
mysql-5.5.27
環境
角色 IP地址
Mysql-Master 192.168.1.10(Mysql對外服務IP)
192.168.1.11(主從同步IP)
MySql-Slave 192.168.1.20(slave對外服務IP)
192.168.1.22(主從同步IP)
主庫授權密碼 tongda
--------------------------------------------------------
1.系統內容準備
關閉防火牆和SELINUX
2.主庫配置步驟
#############################
vim /etc/my.cnf
#########my.cnf################
log-bin=master-bin (開啟mysql-binlog日誌)
server-id=10 (指定mysql-master-id)
###############################
[[email protected]~]# service mysql restart
#########登入mysql##############
mysql> grant replication slave on *.* to [email protected]‘192.168.1.22‘ identified by ‘tongda‘;
mysql> flush privileges;
mysql> reset master
mysql> show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| my-bak.000004 | 2382 | | mysql,mysql |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)
2.從庫配置步驟
#############################
vim /etc/my.cnf
#########my.cnf###############
server-id=20 (指定mysql-slave-id)
##########登入mysql############
mysql> change master to master_host=‘192.168.1.10‘, master_user=‘slave20‘, master_password=‘tongdal‘, master_log_file=‘mysql-bin.000004‘, master_log_pos=2382;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.30
Master_User: slave
Master_Port: 3336
Connect_Retry: 60
Master_Log_File: my-bak.000004
Read_Master_Log_Pos: 2382
Relay_Log_File: ipsan-relay-bin.000013
Relay_Log_Pos: 2525
Relay_Master_Log_File: my-bak.000004
Slave_IO_Running: Yes//從主伺服器讀binlog,存放在本機 Slave_SQL_Running: Yes//讀本地mysqld-relay-bin(中繼日誌),寫入本機mysql
#################################################################
注釋:
master_log_file=‘mysql-bin.*‘, master_log_pos=*;
binlog值和pos值具體需要查看主庫狀態擷取
mysql> show master status; 查看出庫狀態
#####################################################################
mysql主從機器對外服務IP和主從同步IP可為一個網卡或兩個網卡,推薦綁定在兩個網卡並且配置其他網段IP地址
本文出自 “懸劍” 部落格,請務必保留此出處http://sublime.blog.51cto.com/8856101/1545512
Mysql主從複製