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,表示正常
原文地址:http://blog.51cto.com/nhylovezyh/2149644