简单记录下mysql主从同步
vi /etc/my.cnf.d/server.cnf# [mysqld] 新增下面
server_id=100 # 保证唯一
log_bin=/var/log/mariadb/mysql-bin
binlog-do-db=eatlu # 要同步的库
expire_logs_days=3 # 日志文件保存时间
# 重启服务
sudo systemctl restart mariadb
# 登录数据库 进行相关设置
mysql -u root -p
CREATE USER "replica"@"%" IDENTIFIED BY "password";
GRANT REPLICATION SLAVE ON *.* TO "replica"@"%";
FLUSH PRIVILEGES;
# 查看主日志file 和 position
show master status G;
从服务器配置
先将主库的sql导入
修改配置
vi /etc/my.cnf.d/server.cnf
# [mysqld] 新增下面
server_id=101 # 保证唯一
log_bin=/var/log/mariadb/mysql-bin
replicate-do-db=eatlu # 要同步的库
expire_logs_days=3 # 日志文件保存时间
# 重启服务
sudo systemctl restart mariadb
# 登录配置
mysql -u root -p
stop slave;
# 参数修改成主服务器参数
CHANGE MASTER TO MASTER_HOST="192.168.0.1", MASTER_PORT=3306, MASTER_USER="replica", MASTER_PASSWORD="password", MASTER_LOG_FILE="mysql-bin.000002", MASTER_LOG_POS=799;
start slave;
# 查看状态
show slave status G;
# Slave_IO_Running yes
# Slave_SQL_Runniing yes
以上是 简单记录下mysql主从同步 的全部内容, 来源链接: utcz.com/z/533643.html