CentOS7mysql5.6升级5.7

CentOS7mysql5.6升级5.7

前提你的mysql是通过yum安装,其他情况没有测试

检查是否是 yum安装的mysql

yum list installed | grep mysql

删除通过yum安装的 MySQL

yum -y remove mysql-libs.x86_64
yum -y remove mysql-
*

更新yum源

以下 mysql-community-release-el6-5.noarch.rpm 镜像源根据实际情况下载 查看yum源

# 下载镜像源
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

# 本地配置镜像源
yum localinstall mysql-community-release-el6-5.noarch.rpm

# 查看本地镜像源是否生效
yum repolist all | grep mysql

看到的应该是这样的

mysql-connectors-community/x86_64 MySQL Connectors Community         启用:    30
mysql-connectors-community-source MySQL Connectors Community - Sourc 禁用
mysql-tools-community/x86_64      MySQL Tools Community              启用:    40
mysql-tools-community-source      MySQL Tools Community - Source     禁用
mysql55-community/x86_64          MySQL 5.5 Community Server         禁用
mysql55-community-source          MySQL 5.5 Community Server - Sourc 禁用
mysql56-community/x86_64          MySQL 5.6 Community Server         禁用
mysql56-community-source          MySQL 5.6 Community Server - Sourc 禁用
mysql57-community-dmr/x86_64      MySQL 5.7 Community Server Develop 启用:   164
mysql57-community-dmr-source      MySQL 5.7 Community Server Develop 禁用
# 禁用 MySQL 5.5和5.6的源
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
# 启用 MySQL 5.7的源
yum-config-manager --enable mysql57-community-dmr

# 查看是否生效
yum repolist enabled | grep mysql

看到的应该是这样的

mysql-connectors-community/x86_64 MySQL Connectors Community                  30
mysql-tools-community/x86_64      MySQL Tools Community                       40
mysql57-community-dmr/x86_64      MySQL 5.7 Community Server Development M   164

安装 MySQL server

# 安装
yum install mysql-community-server
# 启动
service mysqld start

到这里时有些会报一下错

错误显示:

软件包:mysql-community-server-5.7.20-1.el6.x86_64 (mysql57-community)

需要:libsasl2.so.2()(64bit)

您可以尝试添加 --skip-broken 选项来解决该问题

您可以尝试执行:rpm -Va --nofiles --nodigest

解决方法:

修改vim /etc/yum.repos.d/mysql-community.repo 源文件

[mysql57-community]

name=MySQL 5.7 Community Server

更换目的yum源地址

## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/   

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql   


yum install mysql-community-server #再次安装mysql

安装完成,更新相关配置

不出意外你的mysql应该是没法登录的

# 停掉 mysql
service mysqld stop

# 启动安全模式
mysqld_safe --skip-grant-tables

# 在新的终端登录mysql
mysql

在mysql命令行下修改密码

# 切换数据库
mysql> use mysql;

# 更新密码
mysql> UPDATE user SET authentication_string=PASSWORD('新密码') WHERE  User='root';

# 刷新权限
mysql> flush privileges;

# 退出登录
mysql> exit;

重新启动mysql
service mysqld start

如果在以上几步之后依然无法登录,并且提示:Table 'performance_schema.session_variables' doesn't exist 错误,你可以更新mysql结构,然后重复以上Step4步骤即可,操作如下

mysql_upgrade -u root -p --force