码迷,mamicode.com
首页 > 数据库 > 详细

MYSQL-5.7.20的安装和主从配置(rpm安装包)

时间:2019-04-16 09:16:54      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:unity   roo   local   variable   改密码   emc   alter   for   log   

一,下载解压(包含全部的rpm包)

如果防火墙有屏蔽,先安装rz

  yum install lrzsz -y

  再在本地下载,再上传 https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

二,安装

  安装的过程如果和mariadb包有冲突,如果要有先卸载

  rpm -qa|grep mariadb

  查看已安装的mariadb包

  rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
  rpm -e --nodeps mariadb-5.5.44-2.el7.centos.x86_64
  rpm -e --nodeps mariadb-devel-5.5.44-2.el7.centos.x86_64

  依次先后安装

  rpm -ivh mysql/mysql-community-common-5.7.20-1.el7.x86_64.rpm
  rpm -ivh mysql/mysql-community-libs-5.7.20-1.el7.x86_64.rpm 
  rpm -ivh mysql/mysql-community-client-5.7.20-1.el7.x86_64.rpm 
  rpm -ivh mysql/mysql-community-server-5.7.20-1.el7.x86_64.rpm

三,配置/etc/my.cnf 文件 

[mysqld] 
character-set-server=utf8 

[mysql] 
default-character-set = utf8

[mysql.server]
default-character-set = utf8

[mysqld_safe]
default-character-set = utf8

[client]
default-character-set = utf8
  查看修改后的效果
SHOW VARIABLES LIKE character%;

四,初始化mysql

mysqld --initialize --user=mysql
如有必要指定路径可以加上下面的参数
--basedir=/usr/local/mysql --datadir=/data/mysql

root 用户随机密码保留在/var/log/mysqld.log 文件中

五,启动mysql

systemctl  start  mysqld (启动mysql)
systemctl  restart  mysqld (重启mysql)
systemctl  status  mysqld (查看状态)

六,修改root 初始密码

mysql  -u  root  -p  (使用刚才的随机密码)

  或者 使用下面命令初始化mysql,则不需要密码登录

mysqld --initialize-insecure --user=mysql
mysql -u root --skip-password
alter user root@localhost  identified  by  pwd456;

  如果无法登录,再修改/etc/my.cnf 文件 加入以下参数

skip-grant-tables

  再 systemctl restart mysqld (重启mysql) 就可以无密码登录了,修改密码

update user set authentication_string=password("pwd456") where user="root";
flush privileges;

七,配置主从

  1,修改master /etc/my.cnf 文件

log-bin=mysql-bin
server-id=1
--------下面可以忽略
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
----------------------- 

  2,登录master

GRANT FILE ON *.* TO replicate@xx.xx.xx.xx IDENTIFIED BY pwd123;
GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO replicate@xx.xx.xx.xx IDENTIFIED BY pwd123;

查看状态
SHOW MASTER STATUS \G;

  3,修改slave的配置 /etc/my.cnf 文件

log-bin=mysql-bin                 (非必须项,当slave需要同步的时候才必须)
server-id=2
log_slave_updates = 1
read_only         = 1
slave-skip-errors = all
slave-net-timeout = 60

--------下面可以忽略
binlog-ignore-db=information_schema
binlog-ignore-db=cluster
binlog-ignore-db=mysql
replicate-do-db=ufind_db
replicate-ignore-db=mysql

  4,修改同步选项, 重启slave

change master to master_host=xx.xx.xx.01,master_user=replicate,master_password=pwd123,master_log_file=mysql-bin.000001, master_log_pos=760;

  查看 slave 状态

START SLAVE;
SHOW SLAVE STATUS \G;

  可以看到

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

 

 

参考

mysql的安装 参考 https://jingyan.baidu.com/article/93f9803f010d8fe0e56f555e.html

 

MYSQL-5.7.20的安装和主从配置(rpm安装包)

标签:unity   roo   local   variable   改密码   emc   alter   for   log   

原文地址:https://www.cnblogs.com/tommyjiang/p/10714440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!