闲来无事在虚拟要配置了一遍mysql主从复制,做下记录,配置下来还是蛮简单的

环境:2台#CentOS release 6.8 (Final)虚拟机

[mysql-A]
yum -y update
cat /etc/issue #CentOS release 6.8 (Final)
yum install mysql mysql-devel mysql-server #安装mysql服务器
service mysqld start
service iptables stop
chkconfig iptables off
mysql_secure_installation #初始化mysql参数
vi /etc/my.cnf #server-id=1;log-bin=mysql-bin #添加服务器ID&服务器日志
service mysqld restart
vi .my.cnf > [Client]user=root password=xxx
mysql>CREATE USER 'user'@ 'X.X.X.X' IDENTIFIED BY 'password';#可以创建一个用户专门用来设置成复制账号
grant replication slave on *.* to [email protected]'%' identified by 'passowrd';#赋予“REPLICATION SLAVE”的权限
flush privileges;
flush tables with read lock;#防止数据写入
show master status\G;
netstat -natp | grep -i established.*mysql
mysql -e "SHOW PROCESSLIST"
msyql>UNLOCK TABLES;解锁表
[mysql-B]
vi /etc/my.cnf > server-id=2
service mysqld restart
mysql> change master to
-> master_host='MYSQL-A',
-> master_port='3306', #如未变更可省略
-> master_user='root',
-> master_password='xxx',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=322;
mysql>start slave;
mysql>show processlist;
show slave status \G;

log-bin=mysql-bin

清除mysql主从信息
mysql>slave stop;
mysql>reset slave;
mysql>change master to master_host=’ ‘;