例题:搭建MariaDB数据库服务器,并实现主主复制。
1.在二台服务器中分别MariaDB安装。
2.在二台服务器中分别配置my.cnf文件,开启log_bin。
3.在二台服务器中分别创建专用于数据库同步的用户replication_user,并授权SLAVE。)
4.同步配置,并启用SLAVE复制
5.完成并测试,要求创建“自已姓名的完整汉语拼音”的数据库。
注意:本文中省略了虚拟机的创建和克隆,同时运用了外接软件finalshell来进行远程操作,可通过点击链接来进行finalshell远程连接。
希望能对各位it人士有所帮助,话不多说,我们直接进入主题!!!
yum install mariadb-server -y
yum install -y mariadb
systemctl start mariadb
systemctl enable mariadb
mysql
set password=password('1234')
systemctl start mariadb
sysetmctl enable mariadb
mysql -u root -p
1234
show databases;
eixt
vim /etc/my.cnf
binlog-do-db =pengyuyi
[mariadb]
log-bin
server-id = 1
log-basename = master1
binlog-format = mixed
systemctl stop firewalld
systemctl disable firewalld
systemctl restart mariadb
mysql
show variables like %log_bin%;
如果出现两个value都为on的话,则运行成功
create user 'replication_user'@'%' identified by '1234';
grant replication slave on *.* to 'replication_user'@'%';
show master status;
stop slave;
展示出来的表格为下方这样即可
操作基本上和上方一致
yum install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
mysql
set password=password('1234');
exit
mysql -u root -p
1234
vim /etc/my.cnf
binlog-do-db = pengyuyi
[mariadb]
log-bin
server-id = 2
log-basename = master2
binlog-format = mixed
systemctl stop firewalld
systemctl disabel firewalld
systemctl restart mariadb
show variables like '%log_bin';
create user 'replication_user'@'%' identified by '1234';
grant replication slave on *.* to 'replication_user'@'%';
show master status;
stop slave;
change master to
master_host = '192.168.85.145',
master_user='replication_user',
master_password='1234',
master_port=3306,
master_log_file='master2-bin.000001',
master_log_pos=490,
master_connect_retry=10;
需要根据从虚拟机提供的表格内容进行相对应的更改
start slave;
show slave status \G
出现下面内容中有两个YES,则配置成功
change master to
master_host = '192.168.85.149',
master_user='replication_user',
master_password='1234',
master_port=3306,
master_log_file='master1-bin.000002',
master_log_pos=245,
master_connect_retry=10;
stop slave;
reset slave;
change master to
master_host = '192.168.85.149',
master_user='replication_user',
master_password='1234',
master_port=3306,
master_log_file='master1-bin.000002',
master_log_pos=245,
master_connect_retry=10;
show slave status \G
create database pengyuyi;
show databases;
show databases;
如果有出现pengyuyi这个数据库,则证明MariaBD数据库服务器搭建成功!!!
好了,文章到此就告一段落了,如果本篇博客对您有一定的帮助,麻烦大家记得留言+点赞+收藏喔。创作不易,转载请联系作者!