centos7主从数据库

linux 4个月前 散逸
浏览:152 0

主节点从节点都要执行:
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@localhost ~]# yum install mariadb mariadb-server -y
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
server_id=30(ip地址最后一位)
log_bin=mysql-bin
binlog_ignore_db=mysql

[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# mysql_secure_installation(初始化数据库)

主数据库
MariaDB [(none)]> grant replication slave on . to 'backup'@'%' identified by '123456';(添加权限)
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;(刷新权限)
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql -uroot -p123456
MariaDB [(none)]> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000004
Position: 245
Binlog_Do_DB:
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)

从数据库

MariaDB [(none)]> stop slave
-> ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

MariaDB [(none)]> change master to master_host='192.168.188.20',master_user='backup',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=245;
Query OK, 0 rows affected (0.15 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (3.20 sec)

show slave status\G; //出现两个yes代表成功。

版权声明:散逸 发表于 2019-12-22 0:30:32。
转载请注明:centos7主从数据库 | 散逸

暂无评论

暂无评论...