Mysql 5.6主从同步(和5.1是有不同的):
和5.1不同主要有两处(都在从部分):
1、指定master部分不能写到/etc/my.cnf里了,得在mysql命令里敲
2、启动/停止slave命令为:start/stop/reset slave (5.1是slave在前)
主(和5.1一样):
# mkdir /var/lib/mysql/logs
# chown -R mysql:mysql /var/lib/mysql/logs
# mysql -u root -p123456
> grant replication slave on *.* to ‘ming’@’192.168.1.3’ identified by ‘123456‘;
>flush privileges;
# vi /etc/my.cnf (在[mysqld]下)
server-id = 1 (数据库服务器都有唯一的server-id,通常主服务器制定为1)
log-bin=/var/lib/mysql/logs/log
relay_log=/var/lib/mysql/logs/relaylog
read-only = 0 (主mysql读写都可以)
:wq
# service mysqld restart
# mysql -u root -p123456
> show master status;
或
> show master status \G;
从:
# mkdir /var/lib/mysql/logs
# chown -R mysql:mysql /var/lib/mysql/logs
# vi /etc/my.cnf (在[mysqld]下)
server-id = 2 (原为server-id=1,当然设成非1的其它数字也可以)
log-bin=/var/lib/mysql/logs/log (指定mysql二进制日志路径)
relay_log=/var/lib/mysql/logs/relaylog
read-only=1 (只允许读操作)
# service mysqld restart
# mysql -u root -p123456
> change master to master_host=‘192.168.1.2‘,master_user=‘ming‘,master_password=‘123456‘;
> slave start;
> show slave status \G;
如果以下两项都为yes即是从机配置成功。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes