CentOS下mysql5.6升级5.7指南

2017-01-13 10:48:06来源:oschina作者:CraneH人点击



# CentOS下mysql5.6升级5.7指南
> 前提你的mysql是通过yum安装,其他情况没有测试
### Step 0.
#### 检查是否是 yum安装的mysql
```
yum list installed | grep mysql
```
### Step 1.
#### 删除通过yum安装的 `MySQL`
```
yum -y remove mysql-libs.x86_64
yum -y remove mysql-*
```
### Step 2.
#### 更新yum源
> 以下 `mysql-community-release-el6-5.noarch.rpm` 镜像源根据实际情况下载 [查看yum源](http://dev.mysql.com/downloads/repo/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_64MySQL Tools Community启用:40
mysql-tools-community-sourceMySQL 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_64MySQL 5.7 Community Server Develop 启用: 164
mysql57-community-dmr-sourceMySQL 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 Community30
mysql-tools-community/x86_64MySQL Tools Community40
mysql57-community-dmr/x86_64MySQL 5.7 Community Server Development M 164
```
### Step 3.
#### 安装 MySQL server
```
# 安装
yum install mysql-community-server
# 启动
service mysqld start
```
### Step 4.
#### 安装完成,更新相关配置
> 不出意外你的mysql应该是没法登录的
```
# 停掉 mysql
service mysqld stop
# 启动安全模式
mysqld_safe --skip-grant-tables
# 在新的终端登录mysql
mysql
```
在mysql命令行下修改密码
```
# 切换数据库
mysql> use mysql;
# 更新密码
mysql> UPDATE user SET authentication_string=PASSWORD('新密码') WHEREUser='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
```
# 感谢
[IT_小翼centos升级mysql至5.7](https://my.oschina.net/xuqiang/blog/610285)

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台