CentOS6系列安装MySQL5.7

CentOS6系列,自带的repo库中,默认安装的依然是MySQL5.1版本,过于老旧,而5.6+版本相比5.1版本在各个方面均有全名的提升,对性能要求较高的应用优先考虑5.6+版本。本篇文章介绍使用MySQL官方源安装MySQL5.7

1
2
3
4
shell> cd /usr/local/src
shell> wget http://repo.mysql.com//mysql57-community-release-el6-7.noarch.rpm
shell> rpm -ivh mysql57-community-release-el6-7.noarch.rpm
shell> yum install mysql-server #这里会默认安装mysql-community-server和对应版本的mysql-community-client

如果已经安装有5.1的老版本,可以先将其卸载,再执行上面的安装步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
shell> yum remove mysql
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-5.el6_6 will be erased
--> Processing Dependency: mysql = 5.1.73-5.el6_6 for package: mysql-server-5.1.73-5.el6_6.x86_64
--> Running transaction check
---> Package mysql-server.x86_64 0:5.1.73-5.el6_6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================
Package Arch Version Repository Size
=====================================================================================
Removing:
mysql x86_64 5.1.73-5.el6_6 @base 2.4 M
Removing for dependencies:
mysql-server x86_64 5.1.73-5.el6_6 @base 25 M

Transaction Summary
=====================================================================================
Remove 2 Package(s)

Installed size: 27 M
Is this ok [y/N]:
#卸载老版本的MySQL,默认会同时卸载掉对应的client端

#执行上面的安装部分...

#启动数据库可能会出现下面的错误
shell> service mysqld restart
Stopping mysqld: [ OK ]
MySQL Daemon failed to start.
Starting mysqld: [FAILED]

shell> mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

#查看日志出现如下报错
#[ERROR] Fatal error: mysql.user table is damaged. Please run mysql_upgrade.

#解决方法是重新初始化数据库
shell> rm -fr /var/lib/mysql
shell> mysqld --initialize --user=mysql
shell> service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]

假如老版本的5.1由于某些原因,不能卸载或不允许卸载,那么安装5.7时,可以使用编译安装的方式,将新数据库启动的端口由3306改成3307,即可实现两个MySQL版本的数据库进程共存