CentOS7.3 yum install MySQL5.7

时间:2021-02-22 04:59:05

1.更新 yum mysql5.7 源

  1. #wget http://repo.mysql.com/mysql57-community-release-el6-8.noarch.rpm
  2. #rpm -ivh mysql57-community-release-el6-8.noarch.rpm

2.yum mysql 源配置

  1. 禁用MySQL5.6的源:#yum-config-manager --disable mysql56-community
  2. 启用MySQL5.7的源:#yum-config-manager --enable mysql57-community-dmr

3.查看 mysql install list

  1. #yum repolist enabled | grep mysql

    CentOS7.3 yum install MySQL5.7

4.安装 mysql

  1. #yum install mysql-community-server

这里会报错:

CentOS7.3 yum install MySQL5.7,缺少libsasl2.so.2()(64bit)

解决办法:

  • 修改 yum mysql 源:#vim /etc/yum.repos.d/mysql-community.repo

CentOS7.3 yum install MySQL5.7

[mysql57-community]
        name=MySQL 5.7 Community Server
        ## baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
        baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
        enabled=1
        gpgcheck=0
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

  • 再次安装 mysql: #yum install mysql-community-server

5.配置 mysql 字符集

  • #vim /etc/my.cnf,在文件末尾加上:character-set-server=utf8

CentOS7.3 yum install MySQL5.7

6.启动 mysql 服务

  • #service mysqld start
  • 停止 mysql 服务:#service mysqld stop

7.查询首次安装随机密码

  • #grep 'password' /var/log/mysqld.log |head -n 1

CentOS7.3 yum install MySQL5.7

8.登陆数据库

  • #mysql –u root –p,输入上面查询的密码登陆

9.修改 root 密码

  • 首次登陆进去会出现提示:

You must reset your password using ALTER USER statement before executing this statement.

(在执行此语句之前,必须使用ALTE USER语句重设密码。)

  • 个人学习使用,所以密码设为:root,

alter user user() identified by "root";

但是会报 Your password does not satisfy the current policy requirements.(您的密码不符合当前的策略要求。)

CentOS7.3 yum install MySQL5.7

  • 首先,修改 mysql5.7 的默认密码策略:

1. set global validate_password_policy=0;(密码长度符合即可)

CentOS7.3 yum install MySQL5.7

2. set global validate_password_length=1;(修改密码默认长度为最小值,即4位)

CentOS7.3 yum install MySQL5.7

  • 再次设置密码:alter user user() identified by "root";

CentOS7.3 yum install MySQL5.7

  • exit; 退出,使用新密码登陆 mysql

CentOS7.3 yum install MySQL5.7

10.远程访问

  • 防火墙设置 mysql 端口白名单:#vim /etc/sysconfig/iptables

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

CentOS7.3 yum install MySQL5.7

重启防火墙,#service iptables restart

  • 登陆 mysql 创建远程访问用户’root',密码为’root’:create user 'root'@'%' identified by 'root';

CentOS7.3 yum install MySQL5.7

查询 mysql 库的 user 表:select host, user from user;

CentOS7.3 yum install MySQL5.7

  • 授权:grant all privileges on *.* to 'root'@'%';

CentOS7.3 yum install MySQL5.7

  • 测试

CentOS7.3 yum install MySQL5.7