一级目录
系统环境:centos7
Mysql服务器都已经搭建完成。
主mysql上:
#cp /etc/my.cnf /etc/my.cnf.bak
#vi /etc/my.cnf
#service mysqld restart
登录MySQL
mysql> grant all on . to ‘replication’@’%’ identified by ‘replication’;
mysql> flush privileges;
查看master的状态:
#mysql -uroot -p
mysql> show master status;
从mysql上配置
#vi /etc/my.cnf
#service mysqld restart
#mysql -uroot –p
连接master服务器:
mysql> change master to master_host=‘172.18.49.10’,master_user=‘replication’,master_password=‘replication’,master_log_file=‘master-bin.000003’,master_log_pos=284;
选项解释:
master_host:Master 服务器IP
master_user:Master 服务器授权用户,也就是 Master 前面创建的那个用户
master_password:Master 服务器授权用户对应的密码
master_log_file:Master binlog 文件名
master_log_pos:Master binlog 文件中的 Postion 值
mysql> start slave;
当MariaDB [(none)]> start slave;
报错时:ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
于是查看日志
1.查看SLAVE172.17.206.138上的Mysql报错日志,有这么一句:
141009 6:06:29 [ERROR] Server id not set, will not start slave
意思是,slave的server-id没有设置
从机上面查看端口
MariaDB [(none)]> show variables like ‘server_id’;
±--------------±------+
| Variable_name | Value |
±--------------±------+
| server_id | 0 |
±--------------±------+
命名设置的时2,现在变成了0
主机上面查看
MariaDB [(none)]> show variables like ‘server_id’;
±--------------±------+
| Variable_name | Value |
±--------------±------+
| server_id | 1 |
±--------------±------+
MariaDB [(none)]> stop slave;
测试:
在master上:
mysql> use test;
mysql> create table users(id int(10),name varchar(48),sex char(16));
mysql> insert into users values(1,‘qq’,‘nan’);
mysql> flush privileges;
在slave上:
mysql> use test;
则,主从复制OK!!!
脚本检测MySQL主从以及yes的数量