假設兩台機器 ip 分別為機器一: 192.168.14.37 機器二: 192.168.14.38 ,伺服器為linux R#hel 5.9
##在兩台伺服器中執行建立使用者語句:mysql:>create user 'repl'@'%' identified by '135246'; -- 创建用户 repl 密码 135246
登入後複製
mysql:>grant replication client,replication slave on *.* to 'repl'@'192.168.14.38' identified by '135246'; -- 授权服务器一可以远程访问服务器二
登入後複製
mysql:>grant replication client,replication slave on *.* to 'repl'@'192.168.14.37' identified by '135246'; -- 授权服务器二可以远程访问服务器一
登入後複製
在伺服器一上連接伺服器二
mysql -h 192.168.14.38 -u repl -p
登入後複製
mysql -h 192.168.14.37 -u repl -p
登入後複製
vi /etc/my.cnf
在伺服器1, 新增以下內容:
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] server_id = 1 log-bin character-set-server=utf8 #表名不区分大小写 lower_case_table_names=1 #server_id = 1 # uniquely identify 从为2 show master status
登入後複製
假设服务器一为 " localhost-bin.000004" 和 "120" 服务器二为 " localhost-bin.000005" 和 "667"
登入後複製
stop slave; CHANGE MASTER TO MASTER_HOST = '192.168.14.38', MASTER_USER = 'repl', MASTER_PASSWORD = '135246', MASTER_LOG_FILE = 'localhost-bin.000004', MASTER_LOG_POS = 120; start slave;
登入後複製
stop slave; CHANGE MASTER TO MASTER_HOST = '192.168.14.37', MASTER_USER = 'repl', MASTER_PASSWORD = '135246', MASTER_LOG_FILE = 'localhost-bin.000005', MASTER_LOG_POS = 667; start slave;
登入後複製
mysql:> create database example1 ; use example1; create table example1 (length int);
登入後複製
show slave status \G
mysql影片教學》