参考:
https://blog.csdn.net/D1179869625/article/details/120773725
[root@localhost ~]# vi /etc/my.cnf
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/usr/local/mysql datadir=/data/mysql socket=/tmp/mysql.sock log-error=/data/mysql/mysql.err pid-file=/data/mysql/mysql.pid #character config character_set_server=utf8mb4 symbolic-links=0 explicit_defaults_for_timestamp=true log-bin=mysql-bin server-id=12 log-slave-updates=true innodb_flush_log_at_trx_commit=1 sync_binlog=1
重启数据库,并查看以下配置是否生效
mysql> show variables like 'server_id'; mysql> show variables like 'log_bin'; #skip_networking默认是OFF关闭状态,启用后主从将无法通信 mysql> show variables like '%skip_networking%';
在主库上建立用于主从复制的账号
mysql> CREATE USER 'rep1'@'%'; mysql> GRANT REPLICATION SLAVE ON *.* TO 'rep1'@'%' identified by 'password';
mysql> show master status\G
slave从库配置
在从库上面测试之前建立的复制账号是否可以连接主库
编辑配置文件my.cnf
[mysqld] bind-address=0.0.0.0 port=3306 user=mysql basedir=/usr/local/mysql datadir=/data/mysql socket=/tmp/mysql.sock log-error=/data/mysql/mysql.err pid-file=/data/mysql/mysql.pid #character config character_set_server=utf8mb4 symbolic-links=0 explicit_defaults_for_timestamp=true server-id=15 relay-log=relay-log-bin relay-log-index=slave-relay-bin.index
配置复制参数
# 配置同步,注意 master_log_file 和 master_log_pos 的值要与Master的一致 mysql> CHANGE MASTER TO MASTER_HOST='192.168.169.131',MASTER_USER='rep1',MASTER_PASSWORD='password',MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=682; # 启动同步,如有报错执行 reset slave; mysql> start slave;
查看slave的状态
mysql> show slave status\G
标签:slave,log,show,linux,MASTER,mysql,data,主从 From: https://www.cnblogs.com/cxxtreasure/p/17290665.html