1. 程式人生 > >mariadb主從配置

mariadb主從配置

my.cnf tab pri host system reat read 如果 etc

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主從配置