mysql Ver 8.0.11 for Linux on x86_64 (Source distribution)
CentOS Linux release 7.5.1804 (Core)
查看centos版本命令:cat /etc/redhat-release
分别在二台vps中安装mysql
mysql数据文件目录:vim /usr/local/mysql/var/
mysql配置文件目录:vim /etc/my.cnf
master配置
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
binlog_expire_logs_seconds = 864000
early-plugin-load = ""
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
slave配置
server-id=2
/etc/init.d/mysql start
或者systemctl start mysqld.service
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’; #更新一下用户的密码
FLUSH PRIVILEGES; #刷新权限
查看防火墙状态:systemctl status firewalld
关闭防火墙:systemctl stop firewalld
查看binlog信息
mysql> show master status;
+------------------+----------+--------------+-------------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+-------------------------------------------------+-------------------+
| mysql-bin.000010 | 1590 | | mysql,information_schema,performance_schema,sys | |
+------------------+----------+--------------+-------------------------------------------------+-------------------+
1 row in set (0.00 sec)
执行以下命令
mysql> CHANGE MASTER TO
? ? -> ? ? MASTER_HOST=‘‘,
? ? -> ? ? MASTER_USER=‘‘,
? ? -> ? ? MASTER_PASSWORD=‘‘,
? ? -> ? ? MASTER_LOG_FILE=‘mysql-bin.000010‘,
? ? -> ? ? MASTER_LOG_POS=1590;
开始同步:start slave
查看slave:show status slave
此时服务以及配置好了,在主库创建数据库和表进行测试吧
如果从库发现有同步失败的情况,可以选择忽略
stop slave;
set global SQL_SLAVE_SKIP_COUNTER=1;
show global variables like ‘SQL_SLAVE_SKIP_COUNTER‘;
start slave;
查看binlog内容命令:
show binlog events in ‘bin-log.000010‘
原文:https://blog.51cto.com/13990437/2384970