mariadb主从配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mariadb主从配置相关的知识,希望对你有一定的参考价值。

1、主从2台机器都安装mariadb
yum -y install mariadb mariadb-server
2、登陆mysql
mysql -uroot -p
3、删掉test库
drop database test;
4、创建需要同步的数据库
create database databasename default character set utf8 collate utf8_general_ci;
5、创建同步的用户
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON . TO ‘userdb‘@‘172.xx.xx.xx‘ IDENTIFIED BY ‘x‘x‘xxxxxxxx‘;
6、创建读写用户
GRANT all privileges ON databasename.* TO ‘wruser‘@‘%‘ IDENTIFIED BY ‘xxxxxxxx‘;
7、配置my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-bin=mysql-bin
binlog-format=mixed
server-id=10
binlog-do-db=databasename
binlog-ignore-db=mysql
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d
8、重启mysql
systemctl restart mariadb
9、登陆mysql,查看主机状态
show master status

-> ;

+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 1258 | eoe | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
从机配置
1、主从2台机器都安装mariadb
yum -y install mariadb mariadb-server
2、登陆mysql
mysql -uroot -p
3、删掉test库
drop database test;
4、创建读写用户
GRANT all privileges ON databasename.* TO ‘wruser‘@‘%‘ IDENTIFIED BY ‘xxxxxxxx‘;
5、配置my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
binlog_format=mixed
server-id=14
read-only=on
relay-log=relay-bin
replicate-do-db=eoe
replicate-ignore-db=mysql
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
6、重启mysql
systemctl restart mariadb
7、开始配置从机读写的binlog

change master to
->master_host=‘172.xx.xx.xx‘,
->master_user=‘userdb‘,
->master_password=‘xxxxx‘,
->master_log_file=‘mysql-bin.000004‘,
->master_log_pos=1258;
8、开始从机的表演
start slave;
9、查看从机状态
show slave status;
如果 Slave_SQL_Running 的值为Yes,Seconds_Bebind_Master的值为0,表示正常

以上是关于mariadb主从配置的主要内容,如果未能解决你的问题,请参考以下文章

mariadb数据库的主从复制

mariadb集群配置(主从和多主)

mariadb集群配置(主从和多)

Mysql/MariaDB配置主从复制备份

MariaDB 10.3 主从半同步复制

mariadb主从复制配置