CentOS 6.5/7.2 安装Mysql5.7

在阿里云上搞了一台ECS,尝试装一下mysql,yum自动安装后一开,居然还是5.1版本的,网上请教后才知道,要装5.6,5.7版本还得自己定制一下,记录过程如下。

###准备环境
包括删除老的mysql和下载好文件。

查看已安装的版本

rpm -qa|grep -i mysql

卸载掉

yum remove mysql*

再跑一次查询命令,可以看到没有文件了。

下载安装配置文件
根据这篇文章的说法, 到http://dev.mysql.com/downloads/repo/yum/找要下载文件的链接

wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm

##安装和配置
先安装刚下载的文件

yum localinstall mysql57-community-release-el6-11.noarch.rpm -y

查看一下信息

yum repolist all | grep mysql

可以看到,默认enable的就是5.7版本,所以就直接安装了

yum install mysql-community-server

如果遇到如下错误:

--> Finished Dependency Resolution
Error: Package: 2:postfix-2.10.1-7.el7.x86_64 (base)
           Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
           Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@base)
               libmysqlclient.so.18(libmysqlclient_18)(64bit)
           Obsoleted By: mysql-community-libs-5.7.25-1.el6.x86_64 (mysql57-community)
               Not found
           Updated By: 1:mariadb-libs-5.5.60-1.el7_5.x86_64 (base)
               libmysqlclient.so.18(libmysqlclient_18)(64bit)
Error: Package: 2:postfix-2.10.1-7.el7.x86_64 (base)
           Requires: libmysqlclient.so.18()(64bit)
           Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@base)
               libmysqlclient.so.18()(64bit)
           Obsoleted By: mysql-community-libs-5.7.25-1.el6.x86_64 (mysql57-community)
              ~libmysqlclient.so.20()(64bit)
           Updated By: 1:mariadb-libs-5.5.60-1.el7_5.x86_64 (base)
               libmysqlclient.so.18()(64bit)
Error: Package: mysql-community-server-5.7.25-1.el6.x86_64 (mysql57-community)
           Requires: libsasl2.so.2()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

应该是安装了旧版本的mysql-libs,可以执行:
 yum remove mysql-libs 
 然后再安装
如果遇到如下错误:

Error: Package: mysql-community-server-5.7.25-1.el6.x86_64 (mysql57-community)
           Requires: libsasl2.so.2()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

编辑 /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

修改/el/6/为/el/7/
修改gpgcheck=0
再次安装

启动起来

service mysqld start

进去看一下

mysql -u root
结果不行,报错了
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)

于是又网上找了一圈,解决方法是把登录验证关闭后,设置root密码就可以了。

修改/etc/my.cnf, 在[mysqld]下面加入skip-grant-tables=1
service mysqld restart
mysql -u root 这次可以了

修改root密码

use mysql;
update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
exit;

然后把my.cnf加的语句去掉,重启mysql服务

mysql -u root -p
现在就可以用密码登录了。

###开放远程连接
上面的动作完成后,还只能本机登录, 于是执行如下命令

use mysql;
Grant all on *.*  to 'root'@'%' identified by 'root用户的密码' with grant option;
 这里会报密码不符合规则,因为我设置的密码比较简单,所以还要改一下密码规则设置
set global validate_password_policy=0;
然后再执行上面的语句
flush privileges;

完成后就可以远程连接了。

###参考资料

  • mysql5.7.11修改root默认密码
  • 修改密码验证规则

你可能感兴趣的:(MySQL)