准备俩台虚拟机(版本需要一致,桥接模式关闭防火墙,互相能ping通)
主机:192.168.1.38
从机:192.168.1.48
主机、从机安装ntp
1 [root@localhost ~]#yum -y install ntp ntpdate
主机端配置
1 [root@localhost ~]#vim /etc/my.cnf
进入mysql交互环境
1 [root@localhost ~]# mysql -uroot -p
2 mysql> grant replication slave on *.*to’myslave’@'192.168.1.48’identified by ‘123.com’;
3 mysql> flush privileges; #刷新授权表
查看主库状态
1 mysql> show master status;
从机配置
1 [root@localhost ~]# vim /etc/my.cnf
重启数据库并进入mysql数据库交互模式
1 [root@localhost ~]# /etc/init.d/mysqld restart
2 [root@localhost ~]# mysql -uroot -p
配置从slave从库到master主库的参数
1 mysql> change master to master_host='192.168.1.48',master_user='myslave',master_password='123',master_log_file='mysql-bin.000006',master_logg_pos=579;
1 mysql> start slave;
2 mysql> show slave status\G;
测试
在主机中新建
1 mysql> create database ooo;
2 Query OK, 1 row affected (0.00 sec)
从机中输入下面命令显示
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |