微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mariadb主从

 

实验环境:

  两台centos7

  master:192.168.1.6

  slave:192.168.1.7

 

一、安装mariadb服务

[root@master ~]# yum -y install mariadb-server 

 

二、 初始化mariadb ,编辑配置my.conf文件

[root@master ~]# systemctl restart mariadb

[root@master ~]# MysqL_secure_installation   #初始化数据库

提示一:是否创建root新密码

Enter current password for root (enter for none):

提示一回车后需要设置root的密码。后面的提示一律都回车就行了。)

提示二:是否移除匿名用户登录

Remove anonymous users? [Y/n] 

提示三:是否禁用root用户远程登录

disallow root login remotely? [Y/n]

提示四:是否移除测试(test)数据库的访问权限

Remove test database and access to it? [Y/n] 

提示五:是否立即生效

load privilege tables Now? [Y/n]

 

[root@master ~]# vim /etc/my.cnf  #修改配置my.cnf文件

 

 

 

[root@master ~]# systemctl restart mariadb 

 

三、在主数据库进行授权。

[root@master ~]# MysqL -uroot -p123

MariaDB [(none)]> grant replication slave on *.* to 'ml'@'%' IDENTIFIED by '123';

 

 

图上这个是很重要的。

 

四、从数据库配置:

 

安装→启动→初始化  ------------   在上面有提到这些步骤怎么做

 

 

 

[root@slave ~]# vim /etc/my.cnf

 

 

 

 

[root@slave ~]# systemctl restart mariadb

[root@slave ~]# MysqL -uroot -p123

 

MariaDB [(none)]> change master to master_host='192.168.1.6', master_user='ml', master_password='123', master_log_file='log.000001', master_log_pos=724;  #这两个需要去show master status去看(注意:会变的。)

 

MariaDB [(none)]> start slave;

 

MariaDB [(none)]> show slave status \G

 

 

 

测试:

主:

MariaDB [(none)]> create database test;

从:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐