标签:http mirrors star user 连接 pass 数据库版本 节点 res
mysql主从配置
yum配置
[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
服务器1: MariaDB01 192.168.254.24
服务器2: MariaDB02 192.168.254.25
操作系统: CentOS7.3
数据库版本: MariaDB-10.3.7
主从关系: MariaDB01为主,MariaDB02为从
MariaDB01
1. 修改配置文件
vi /etc/my.cnf.d/server.cnf
在[mysqld]下加入以下
server-id=1
log-bin=mysql-bin
2. 重启mysql服务
service mysqld restart
3.登录数据库
mysql -uroot
delete from user where user=‘‘;
show master status
create user ‘sync_user‘@‘%‘ identified by ‘123456‘;
grant replication slave on *.* to sync_user;
flush privileges;
MariaDB02
1. 修改配置文件
vi /etc/my.cnf.d/server.cnf
在[mysqld]下加入以下
server-id=2
log-bin=mysql-bin
2. 重启mysql服务
service mysqld restart
3.登录数据库
mysql -uroot
delete from user where user=‘‘;
4
. 创建主从连接帐号与授权
CREATE USER ‘repl‘@‘%‘ IDENTIFIED BY ‘123456‘;
GRANT REPLICATION SLAVE ON *.* TO ‘repl‘@‘%‘;
5. 建立主从连接
CHANGE MASTER TO MASTER_HOST=‘192.168.254.24‘, MASTER_USER=‘repl‘, MASTER_PASSWORD=‘123456‘, MASTER_LOG_FILE=‘mysql-bin.000001‘, MASTER_LOG_POS=328;
start slave;
6.验证!!!
create database test01
use test01
create table students(id int(10), name char(20), age int(10))
之后查看从节点是否有test01数据库和students表
7.查看mysql二进制log
mysqlbinlog /var/lib/mysql/mysql-bin.000001
标签:http mirrors star user 连接 pass 数据库版本 节点 res
原文地址:https://www.cnblogs.com/fengzi7314/p/9940949.html