linux MySQL与mariadb 主从服务器搭建

主服务器: IP:192.168.88.80 mariadb
从服务器: IP:192.168.88.88 MySQL

一 、 主服务器搭建

1,安装mariadb
[root@localhost ~]# yum install mariadb-server mariadb
遇到 Is this ok [y/d/N]:
输入 y
安装完成后,先启动服务 systemctl start mariadb
设置开机启动 systemctl enable mariadb
2,登录,修改密码
[root@localhost ~]# vi /etc/my.cnf
在[mysqld]下面输入 skip-grant-tables
保存退出,重启mysql服务
systemctl restart mariadb
重启完成后,直接输入mysql进入
[root@localhost ~]# mysql
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SET password for ‘root’@‘localhost’=password(‘新密码’);
MariaDB [(none)]> exit;
[root@localhost ~]# vi /etc/my.cnf
删除刚刚输入的: skip-grant-tables (这一步很重要)
重启服务:systemctl restart mariadb

二 、从服务器搭建

1、 安装mysql
	为方便安装,采用yum 方式
	[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
	[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
	[root@localhost ~]# yum -y install mysql-community-server
	安装mysql很慢,可以先去吃个饭,睡个午觉再来
	安装完成后,启动mysql服务  systemctl start mysqld.service
2,修改密码
 [root@localhost ~]#  vi  /etc/my.cnf
 在[mysqld]下面输入  skip-grant-tables
 保存退出,重启mysql服务
systemctl restart mysqld.service
重启完成后,直接输入mysql进入
[root@localhost ~]# mysql
mysql> flush privileges;
mysql> 	update mysql.user set authentication_string=password('newpassword') where user='root';
mysql> exit;
[root@localhost ~]#  vi  /etc/my.cnf

删除刚刚输入的: skip-grant-tables (这一步很重要)
重启服务:systemctl restart mysqld.service
yum -y remove mysql57-community-release-el7-10.noarch(因为安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉)

三 ,主从搭建

1,主服务器导出对应的库,从服务器导入刚导出的库。主从服务器上就不能进行数据库的增删改操作。
2,主服务器:
1, [root@localhost ~]# vi /etc/my.cnf
2,[mysqld]下面添加以下参数 :
server-id=1 #与从服务器值不同
log-bin=mysql-bin #启动MySQL二进制日志系统
binlog-do-db=newdb #需要同步的数据库
binlog-ignore-db=information_schema,performance_schema,mysql #不需要同步的数据库
3,重启服务 systemctl restart mariadb
4,登录 授权 grant replication slave on . to ‘root’@‘192.168.88.88’ identified by ‘newpassword’;
5, 刷新权限 flush privileges;
6,查看状态 show master status \G
在这里插入图片描述
3,从服务器配置:
1, vi /etc/my.cnf 输入以下配置:
server-id=3 #设置从服务器id,必须与主服务器不同
log-bin=mysql-bin #启动MySQ二进制日志系统
replicate-do-db=newdb #需要同步的数据库名
replicate-ignore-db=information_schema,performance_schema,mysql #不需要同步的数据库名
2,重启服务 systemctl restart mysqld.service
3, 登录mysql
mysql> stop slave;
change master to master_host=‘192.168.88.80’,master_user=‘root’,master_password=‘newpassword’,master_log_file=‘mysql-bin.000001’,master_log_pos=557;
start slave;
4,查看状态 show slave status \G
mysql> show slave status\G *************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.88.80
Master_User:root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 261
Relay_Log_File: template-relay-bin.000002
Relay_Log_Pos: 557
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 261
Relay_Log_Space: 412
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 255
1 row in set (0.00 sec)

测试

1,自己去测试吧,我就不写出来了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值