mariadb主从同步配置

1. 主库上操作

(1)Linux命令行操作
# 安装mariadb(Maser and Slave)
yum -y install mariadb mariadb-server

# 数据库主库配置(Master)
sed -i '/[mysqld]/aserver-id=1 
log-bin=mysql-bin' /etc/my.cnf

# 启动数据库并加入自启动服务(Master and Slave)
systemctl start mariadb
systemctl enable mariadb
(2) 数据库内操作
# 授权主从同步用户和主机
grant replication slave on *.* to tongbu@'%' identified by '123456';
flush privileges;
show master status;

2.从库上操作

(1)Linux命令行操作
# 数据库从库配置(Slave)
sed -i '/[mysqld]/aserver-id=2 ' /etc/my.cnf

# 重启从数据库(Slave)
systemctl restart mariadb
(2) 数据库内操作
# 连接主库
change master to master_host='172.16.1.51',master_user='tongbu',master_password='123456',
master_log_file='mysql-bin.000001',master_log_pos=462;

# 启动从库IO线程
start slave io_thread;
# 从库跳过错误
set global sql_slave_skip_counter=1;
# 启动从库
start slave;
原文地址:https://www.cnblogs.com/IMSCZ/p/12108571.html