准备俩台虚拟机(版本需要一致,桥接模式关闭防火墙,互相能ping通)
主机:192.168.1.38
从机:192.168.1.48
主机、从机安装ntp
[root@localhost ~]#yum -y install ntp ntpdate
主机端配置
[root@localhost ~]#vim /etc/my.cnf
进入mysql交互环境
[root@localhost ~]# mysql -uroot -p
mysql> grant replication slave on *.*to’myslave’@'192.168.1.48’identified by ‘123.com’;
mysql> flush privileges; #刷新授权表
查看主库状态
mysql> show master status;
从机配置
[root@localhost ~]# vim /etc/my.cnf
重启数据库并进入mysql数据库交互模式
[root@localhost ~]# /etc/init.d/mysqld restart
[root@localhost ~]# mysql -uroot -p
配置从slave从库到master主库的参数
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;
mysql> start slave;
mysql> show slave status\G;
测试
在主机中新建
mysql> create database ooo;
Query OK, 1 row affected (0.00 sec)
从机中输入下面命令显示
mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
来源:CSDN
作者:ni gei wo gong
链接:https://blog.csdn.net/weixin_46083627/article/details/103728500