- 1、删除已经安装的mysql(已经确定安装过了,不确定就输入
yum list installed | grep mysql
看看)
yum remove mysql mysql-server mysql-libs mysql-server;`
yum -y remove mysql-libs.x86_64`
find / -name mysql
将找到的相关东西全删掉,尤其是后缀为sock的文件所在的文件夹,不然安装新版本后可能不能重启
- 2、更新yum源 (这时候要是报错:
You need to install yum-utils to use yum-config-manager
,就得先安装yum-utils
)
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
然后发现yum repolist all | grep mysql
后没有内容,说明其实yum是没有更新的,那就只能手动添加源了,过程如下:
rpm -Uvh mysql57-community-release-el6-n.noarch.rpm //1、更新rpm源
找到/etc/yum.repos.d/mysql-community.repo
文件 (要是文件夹和文件都不存在,就自己建立) 写入:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
源更新完成
- 3、把可用源不要的关掉,要用的打开,再查看可用源,就是mysql5.7了(手动添加的源就跳过吧。。)
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
yum repolist enabled | grep mysql
- 4、安装mysql
yum install mysql-community-server
如果是最小安装情况下,这时候很可能在下载后需要按下Y/N后报错:epel-release is not installed
那就要安装epel-release:yum install epel-release
然后报错有可能就变成:[Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
这种情况下,找到/etc/yum.repos.d/epel.repo
文件夹,写入:
```
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=0 //这里是重点,必须调整成0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
```
然后再yum install mysql-community-server
就可以成功了
- 5、如果需要就调整
/etc/my.cnf
里配置 - 6、启动服务
service mysqld start
- 7、 查看mysql是否自启动,并且设置开启自启动
chkconfig --list | grep mysqld
chkconfig mysqld on
- 8、mysql安全设置
mysql_secure_installation