①创建虚拟机,安装mysql、jdk等。
参考:电商六十八、搭建mysql集群。三台mysql机器节点。
②安装keepalived。
参考:电商六十二、Nginx负载均衡高可用、keepalived+nginx实现Nginx集群、主分发器和两台备分发器(可以多台备分发器)
③在mysql上配置keepalived.cnf文件。
利用软件连接192.168.10.168
192.168.10.167上的keepalived.cnf内容为:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.167
unicast_peer {
192.168.10.168
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.167
unicast_peer {
192.168.10.168
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
192.168.10.168上的keepalived.cnf的内容为:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.168
unicast_peer {
192.168.10.167
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.168
unicast_peer {
192.168.10.167
192.168.10.169
}
virtual_ipaddress {
192.168.100.101
}
}
192.168.10.169上的keepalived.cnf的内容为:
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.169
unicast_peer {
192.168.10.167
192.168.10.168
}
virtual_ipaddress {
192.168.100.101
}
}
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh"
interval 2
}
vrrp_sync_group VG1 {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
# nopreempt
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 1234
}
track_script {
check_run
}
notify_master /home/mysql/master.sh
notify_stop /home/mysql/stop.sh
unicast_src_ip 192.168.10.169
unicast_peer {
192.168.10.167
192.168.10.168
}
virtual_ipaddress {
192.168.100.101
}
}
④创建脚本文件:
/home/mysql/mysql_check.sh
/home/mysql/master.sh
/home/mysql/stop.sh
而且内容都要用到/home/mysql/.bashrc
在home目录下创建文件夹mysql
cd /home
mkdir mysql
然后在目录/home/mysql下创建文件mysql_check.sh、master.sh、stop.sh、.bashrc
然后在软件中修改内容:但是在这个上面修改,:set ff 为dos,所以不在这个上面改。
master.sh内容为:
#!/bin/bash
. /home/mysql/.bashrc
Master_Log_File=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Master_Log_File | awk -F": " '{print $2}')
Relay_Master_Log_File=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Relay_Master_Log_File | awk -F": " '{print $2}')
Read_Master_Log_Pos=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Read_Master_Log_Pos | awk -F": " '{print $2}')
Exec_Master_Log_Pos=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Exec_Master_Log_Pos | awk -F": " '{print $2}')
i=1
while true
do
if [ $Master_Log_File = $Relay_Master_Log_File ] && [ $Read_Master_Log_Pos -eq $Exec_Master_Log_Pos ]
then
echo "ok"
break
else
sleep 1
if [ $i -gt 60 ]
then
break
fi
continue
let i++
fi
done
mysql -uroot -S /data/mysql.sock -e "stop slave;"
mysql -uroot -S /data/mysql.sock -e "reset slave all;"
mysql -uroot -S /data/mysql.sock -e "reset master;"
mysql -uroot -S /data/mysql.sock -e "show master status;" > /tmp/master_status_$(date "+%y%m%d-%H%M").txt
#!/bin/bash
. /home/mysql/.bashrc
Master_Log_File=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Master_Log_File | awk -F": " '{print $2}')
Relay_Master_Log_File=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Relay_Master_Log_File | awk -F": " '{print $2}')
Read_Master_Log_Pos=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Read_Master_Log_Pos | awk -F": " '{print $2}')
Exec_Master_Log_Pos=$(mysql -uroot -S /data/mysql.sock -e "show slave status\G" | grep -w Exec_Master_Log_Pos | awk -F": " '{print $2}')
i=1
while true
do
if [ $Master_Log_File = $Relay_Master_Log_File ] && [ $Read_Master_Log_Pos -eq $Exec_Master_Log_Pos ]
then
echo "ok"
break
else
sleep 1
if [ $i -gt 60 ]
then
break
fi
continue
let i++
fi
done
mysql -uroot -S /data/mysql.sock -e "stop slave;"
mysql -uroot -S /data/mysql.sock -e "reset slave all;"
mysql -uroot -S /data/mysql.sock -e "reset master;"
mysql -uroot -S /data/mysql.sock -e "show master status;" > /tmp/master_status_$(date "+%y%m%d-%H%M").txt
mysql_check.sh内容为:
#!/bin/bash
c=`netstat -tnlp | grep 3306 | wc -l`
if [ $c != 1 ]; then
service keepalived stop
fi
#!/bin/bash
c=`netstat -tnlp | grep 3306 | wc -l`
if [ $c != 1 ]; then
service keepalived stop
fi
stop.sh的内容为:
#!/bin/bash
. /home/mysql/.bashrc
M_File1=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/File/{print $2}')
M_Position1=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/Position/{print $2}')
sleep 1
M_File2=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/File/{print $2}')
M_Position2=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/Position/{print $2}')
i=1
while true
do
if [ $M_File1 = $M_File1 ] && [ $M_Position1 -eq $M_Position2 ]
then
echo "ok"
break
else
sleep 1
if [ $i -gt 60 ]
then
break
fi
continue
let i++
fi
done
#!/bin/bash
. /home/mysql/.bashrc
M_File1=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/File/{print $2}')
M_Position1=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/Position/{print $2}')
sleep 1
M_File2=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/File/{print $2}')
M_Position2=$(mysql -uroot -S /data/mysql.sock -e "show master status\G" | awk -F': ' '/Position/{print $2}')
i=1
while true
do
if [ $M_File1 = $M_File1 ] && [ $M_Position1 -eq $M_Position2 ]
then
echo "ok"
break
else
sleep 1
if [ $i -gt 60 ]
then
break
fi
continue
let i++
fi
done
然后分别赋予权限。
chmod +x /home/mysql/mysql_check.sh
chmod +x /home/mysql/master.sh
chmod +x /home/mysql/stop.sh
chmod +x /home/mysql/.bashrc
ip a查看虚拟IP绑定在哪一台机器的哪一个网卡接口
重启mysql和keepalived
service mysql restart
service keepalived restart
⑤mysql数据库主主同步。
mysql主主同步,即其中任意一台服务器改变,另一台服务器也跟着改变。
注意下面几点:
1)要保证同步服务期间之间的网络联通。即能相互
ping
通,能使用对方授权信息连接到对方数据库(防火墙开放3306端口)。
2)关闭selinux。
vi /etc/selinux/config
把SELINUX=enforce 改成disabled就可以了,重启电脑,永久生效
getenforce 查看,如果为disabled 就是已经关闭,如果enforce 就是强制的模式。
3)同步前,双方数据库中需要同步的数据要保持一致。这样,同步环境实现后,再次更新的数据就会如期同步了。
4)温馨提示:
在做主主同步前,提醒下需要特别注意的一个问题:
主主复制和主从复制有一些区别,因为多主中都可以对服务器有写权限,所以设计到自增长重复问题,例如:
出现的问题(多主自增长ID重复)
首先在A和B两个库上创建
test
表结构;
停掉A,在B上对数据表
test
(存在自增长属性的ID字段)执行插入操作,返回插入ID为1;
然后停掉B,在A上对数据表
test
(存在自增长属性的ID字段)执行插入操作,返回的插入ID也是1;
然后 同时启动A,B,就会出现主键ID重复
5)解决方法:
只要保证两台服务器上的数据库里插入的自增长数据不同就可以了
如:A插入奇数ID,B插入偶数ID,当然如果服务器多的话,还可以自定义算法,只要不同就可以了
在下面例子中,在两台主主服务器上加入参数,以实现奇偶插入!
记住:在做主主同步时需要设置自增长的两个相关配置,如下:
auto_increment_offset 表示自增长字段从那个数开始,取值范围是1 .. 65535。这个就是序号。如果有n台mysql机器,则从第一台开始分为设1,2...n
auto_increment_increment 表示自增长字段每次递增的量,其默认值是1,取值范围是1 .. 65535。如果有n台mysql机器,这个值就设置为n。
在主主同步配置时,需要将两台服务器的:
auto_increment_increment 增长量都配置为2
auto_increment_offset 分别配置为1和2。这是序号,第一台从1开始,第二台就是2,以此类推.....
这样才可以避免两台服务器同时做更新时自增长字段的值之间发生冲突。(针对的是有自增长属性的字段)
在主主配置时,如果是三台机器:
auto_increment_offset 分别第一台机器为1、第二台机器为2、第三台机器为3
auto_increment_increment
因为有三台机器,所以每台机器的这个值都是3
6)在mysql机器上的my.cnf配置:
192.168.10.167上的my.cnf:
vi /etc/my.cnf
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
auto_increment_offset=1
auto_increment_increment=3
master_info_repository =table
relay_log_info_repository =table
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 300 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test3 #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
auto_increment_offset=1
auto_increment_increment=3
master_info_repository =table
relay_log_info_repository =table
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 300 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test3 #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
重启mysql。service mysql restart
192.168.10.168上的my.cnf:
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
auto_increment_offset=2
auto_increment_increment=3
master_info_repository =table
relay_log_info_repository =table
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 400 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test4 #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
auto_increment_offset=2
auto_increment_increment=3
master_info_repository =table
relay_log_info_repository =table
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 400 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test4 #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
然后重新启动mysql。service mysql restart
192.168.10.169上的my.cnf:
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
auto_increment_offset=3
auto_increment_increment=3
master_info_repository =table
relay_log_info_repository =table
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 500 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test5 #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[client]
port = 3306
default-character-set = utf8mb4
[mysql]
port = 3306
default-character-set = utf8mb4
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
auto_increment_offset=3
auto_increment_increment=3
master_info_repository =table
relay_log_info_repository =table
##########################
# summary
##########################
#bind-address = 0.0.0.0
#port = 3306
#datadir=/datavol/mysql/data #数据存储目录
##########################
# log bin
##########################
server-id = 500 #必须唯一
log_bin = mysql-bin #开启及设置二进制日志文件名称
binlog_format = MIXED
sync_binlog = 1
expire_logs_days =7 #二进制日志自动删除/过期的天数。默认值为0,表示不自动删除。
#binlog_cache_size = 128m
#max_binlog_cache_size = 512m
#max_binlog_size = 256M
binlog-do-db = test5 #要同步的数据库
binlog-ignore-db = mysql #不需要同步的数据库
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
##########################
# character set
##########################
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
重启mysql。service mysql restart
创建授权用户(三台节点,均要进行此操作)
mysql -u root -p
密码:123456(mysql5.7的)
grant replication slave on *.* to 'slave'@'%' identified by '123456';
log_bin是否开启(三台节点,均要进行此操作)
show variables like 'log_bin';
查看master状态(三台节点,均要进行此操作,并记住结果)
show master status \G;
192.168.10.167
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000004
Position: 435
Binlog_Do_DB: test3
Binlog_Ignore_DB: mysql,information_schema,performation_schema,sys
Executed_Gtid_Set:
1 row in set (0.00 sec)
ERROR:
No query specified
192.168.10.168
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000004
Position: 435
Binlog_Do_DB: test4
Binlog_Ignore_DB: mysql,information_schema,performation_schema,sys
Executed_Gtid_Set:
1 row in set (0.00 sec)
ERROR:
No query specified
192.168.10.169
mysql> show master status \G;
*************************** 1. row ***************************
File: mysql-bin.000005
Position: 435
Binlog_Do_DB: test5
Binlog_Ignore_DB: mysql,information_schema,performation_schema,sys
Executed_Gtid_Set:
1 row in set (0.00 sec)
ERROR:
No query specified
7)数据同步授权(iptables防火墙开启3306端口,要确保对方机器能使用下面权限连接到本机mysql),执行主张同步操作。
192.168.10.167机器上:
mysql> unlock tables;
//
先解锁,将对方数据同步到自己的数据库中
mysql> stop slave;
mysql>
CHANGE MASTER TO MASTER_HOST='192.168.10.168', MASTER_PORT=3306, MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=435 FOR CHANNEL '300';
注意:405和for channel之间只能有一个空格。
mysql>
CHANGE MASTER TO MASTER_HOST='192.168.10.169', MASTER_PORT=3306, MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=435 for channel '400';
mysql> start slave;
mysql> show slave status \G;
yes
yes
192.168.10.168机器上:
mysql> unlock tables;
//
先解锁,将对方数据同步到自己的数据库中
mysql> stop slave;
mysql>
CHANGE MASTER TO MASTER_HOST='192.168.10.167', MASTER_PORT=3306, MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=435 FOR CHANNEL '500';
注意:405和for channel之间只能有一个空格。
mysql>
CHANGE MASTER TO MASTER_HOST='192.168.10.169', MASTER_PORT=3306, MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=435 for channel '400';
mysql> start slave;
mysql> show slave status \G;
四个yes则正确。
192.168.10.169机器上:
mysql> unlock tables;
//
先解锁,将对方数据同步到自己的数据库中
mysql> stop slave;
mysql>
CHANGE MASTER TO MASTER_HOST='192.168.10.167', MASTER_PORT=3306, MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=435 FOR CHANNEL '500';
注意:405和for channel之间只能有一个空格。
mysql>
CHANGE MASTER TO MASTER_HOST='192.168.10.168', MASTER_PORT=3306, MASTER_USER='slave', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=435 for channel '300';
mysql> start slave;
mysql> show slave status \G;
测试: