1.安装mysql数据库
参考过好多文章,最后发现这个最好
https://www.jb51.net/article/148189.htm
2.主从配置
①先明确两个数据库的ip地址 ifconfig命令
②master配置
1)更改/etc/my.cnf文件 添加 server-id=1
log-bin=master-bin
log-bin-index=master-bin.index
2)重启mysql服务 service mysqld restart
3)创建用户repl以及相关权限配置
use mysql
create repl
grant replication slave on *.* to 'repl'@'ip地址' identified by 'mysql'
flush privilages
③slave配置
1)更改/etc/my.cnf 文件 添加
server-id=2
relay-log=slave-relay-bin
relay-log-index=slave-rerelay-bin.index
2)配置主从
change master to master_host='172.17.58.172',master_port=3306,master_user='repl',master_password='mysql',master_log_file='master-bin.000001',master_log_pos=0;
3.测试配置
在master中创建一个数据库,看看slave中是否更新
show master status
show slave status \G
查看两种配置是否对应