CentOS 6.5 安装MySQL5.7 RPM

时间:2022-06-15 14:30:49

一、新特性

MySQL 5.7可谓是一个令人激动的里程碑,在默认了InnoDB引擎的基础上,新增了ssl、json、虚拟列等新特性。相对于postgreSQL和MariaDB而言,MySQL5.7做了大量“补短”操作。

特性详解:

原文:http://mysqlserverteam.com/whats-new-in-mysql-5-7-generally-available/

翻译:http://www.oschina.net/translate/whats-new-in-mysql-5-7-generally-available

二、升级操作

1、卸载旧版本

1.1、查看MySQL

rpm -qa|grep mysql
rpm -qa|grep mariadb

CentOS 6.5 安装MySQL5.7 RPM

1.2、卸载MySQL

rpm -e --nodeps mysql-5.1.-.el6.x86_64
rpm -e --nodeps mysql-connector-odbc-5.1.5r1144-.el6.x86_64
rpm -e --nodeps mysql-libs-5.1.-.el6.x86_64
rpm -qa|grep mysql

1.3、删除数据目录

ls  -l  /var/lib|grep mysql
rm -rf /var/lib/mysql

数据目录可以备份移走。mysqld服务在初始化时会检查数据目录是否存在:如果数据目录不存在,mysqld则会创建它;如果数据目录存在,且不是空目录(即包含有文件或子目录),mysqld会显示一条错误信息并中止:
[ERROR] --initialize specified but the data directory exists. Aborting.

2、安装MySQL5.7

2.1、解压MySQL5.7

tar -xvf mysql-5.7.-.el6.x86_64.rpm-bundle.tar

CentOS 6.5 安装MySQL5.7 RPM

顺便提醒,安装环境是CentOS6.5,所以应该选用el6的安装包;CentOS7应该选用el7安装包。

如果安装包对应的系统版本不正确,安装时会出现有关glibc的依赖错误:

warning: mysql-community-libs-5.7.14-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libc.so.6(GLIBC_2.14)(64bit) is needed by mysql-community-libs-5.7.14-1.el7.x86_64

若出现libnuma相关的依赖错误,则需要使用yum安装numactl

error: Failed dependencies:

libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.17-1.el7.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.17-1.el7.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.17-1.el7.x86_64

2.2、按照依赖关系依次安装rpm包
依赖关系依次为common→libs→client→server

rpm -ivh mysql-community-common-5.7.-.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.-.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.-.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.-.el6.x86_64.rpm

CentOS 6.5 安装MySQL5.7 RPM

不要想着偷懒,client也是需要装的···

3、初始化MySQL5.7

3.1、启动mysqld服务

cd ../sbin
service mysqld start

CentOS 6.5 安装MySQL5.7 RPM

无需手动初始化,启动时间较长,耐心等待一下

3.2、检查mysqld运行状态

service mysqld status

CentOS 6.5 安装MySQL5.7 RPM

至此可以判断MySQL基本安装成功了

3.3、找到临时登录密码

vi /var/log/mysqld.log

CentOS 6.5 安装MySQL5.7 RPM

3.4、登录

mysql -uroot -p

CentOS 6.5 安装MySQL5.7 RPM

4、配置MySQL远程访问

4.1、修改root密码

alter user 'root'@'localhost' identified by 'abc@123';

在5.6后,mysql内置密码增强机制,低强度密码会报错:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

4.2、添加远程登录用户

use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'abc@123' WITH GRANT OPTION;

'%'代表任意地址,也可以指定IP

4.3、检查用户表,刷新内存权限

select host, user from user;
FLUSH PRIVILEGES;

CentOS 6.5 安装MySQL5.7 RPM

4.4、设置防火墙

vi /etc/sysconfig/iptables

在-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited之前,添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport  -j ACCEPT

4.5、重启防火墙

service iptables restart

CentOS 6.5 安装MySQL5.7 RPM