centos7 mysql5.7 yum 安装到部署mysql 主从服务器

1.安装mysql yum下载源

     wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

    rpm -ivh mysql-community-release-el7-5.noarch.rpm

2.mysql服务器安装

    yum install mysql-server mysql-devel -y

3.mysql utf8配置

在mysql配置文件/etc/my.cnf的[mysqld]中加入character-set-server=utf8

4.启动mysql服务

service mysqld start

刚安装密码为空,直接按回车

5.修改mysql登录密码

use mysql;

UPDATE user SET password=password("你的密码") WHERE user='root';

刷新权限

FLUSH PRIVILEGES;

到此处mysql已经配置完成

首先还是设置防火墙策略  默认为firewalld  可以指定访问ip

我的两台服务器均为centos7   mysql5.7  master的ip172.18.10.2 slave的ip172.18.10.3

分别添加规则  改改ip

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.18.10.2" port protocol="tcp" port="3306" accept"

输错了就删除策略从来

firewall-cmd --permanent  --remove-rich-rule="rule family="ipv4" source address="172.18.10.2" port protocol="tcp" port="3306" accept"

然后先配置master 的mysql的my.cnf文件

vi /etc/my.cnf

在[mysqld]中添加:

server-id = 1

log_bin = master-bin

log_bin_index = master-bin.index

binlog_do_db = my_data

binlog_ignore_db = mysql

备注:server-id 服务器唯一标识,log_bin 启动MySQL二进制日志,binlog_do_db 指定记录二进制日志的数据库,binlog_ignore_db 指定不记录二进制日志的数据库。

重启数据库

service mysql restart

登录mysql配置访问权限

use mysql;

创建一个主从复制用户

create user hong identified by '123456';

设置其它机器root可访问数据库(可以不用配置)

grant all privileges on *.*  to 'root'@'%' identified by 'root密码' with grant option;

指定主从复制用户权限

grant replication slave on *.* to 'hong' @'172.18.10.3(从服务器ip)' identified by '123456';

刷新权限

FLUSH PRIVILEGES;

重启mysql

service mysql restart

show master status;

记下两个东西待会儿要用

File 和Position

主服务器就搞定了

然后是从服务器

编辑mysql.cnf文件

vi /etc/my.cnf

在[mysqld]中添加:

server-id = 2

relay-log = slave-relay-bin

relay-log-index = slave-relay-bin.index

然后重启mysql

service mysql restart

登录mysql

use mysql;

change master to master_host='主服务器ip',master_port=3306,master_user='hong',master_password='123456',master_log_file='File对应的',master_log_pos=Position对应;

刷新权限

FLUSH PRIVILEGES;

启动slave服务器

start slave;

停止是stop slave;

然后看slave状态

show slave status\G;

Slave_IO_Running和Slave_SQL_Running都为yes才表示同步成功。

OVER

猜你喜欢

转载自blog.csdn.net/LaySolitary/article/details/82623658
今日推荐