Centos7 安装 mysql5.7.23

版权声明:任何组织或个人禁止未经本人允许在任何媒介上发表或转载本人的文章、图片等,如需转载,请联系[email protected],转载后必须注明出处(https://blog.csdn.net/qq_40523572)和原博主(渡一) https://blog.csdn.net/qq_40523572/article/details/83016334
  1. 下载mysql yum包
    http://dev.mysql.com/downloads/repo/yum/

  2. 安装yum包

    rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
    
  3. 安装mysql,此过程需要一定时间

    yum install  -y  mysql-community-server
    
  4. 启动mysql

    service mysqld start
    
  5. 查看mysql的状态

    service mysqld status
    
  6. 获取临时密码,因为是rpm安装,error log文件在/var/log/mysqld.log

    grep 'temporary password' /var/log/mysqld.log
    

    在这里插入图片描述

  7. 登录并修改密码

    mysql -uroot -p 临时密码
    alter user 'root'@'localhost' identified by '123456';
    

    此时会报错:
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    必须修改两个全局的参数:

    5.7:
    set global validate_password_policy=0;
    set global validate_password_length=1;
    5.8:
    set global validate_password.policy=0;
    set global validate_password.length=1;
    
  8. 授权远程登录

    create user  'admin'@'%'  identified by '123456';
    grant all on  *.*  to  'admin'@'%';
    flush privileges;
    
  9. 开机自启动

    chkconfig --levels 235 mysqld on
    
  10. 设置字符集

    vim /etc/my.cnf
    
    [mysqld]   
    character_set_server = utf8
    
    [mysql]
    default-character-set = utf8
    
    查看:
    SHOW VARIABLES LIKE 'character%' 
    
  11. 远程连接报错相关
    mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password。

 # 修改加密规则
 alter user 'root'@'localhost' identified by '123456' password expire never;
 # 更新用户密码
 alter user 'root'@'localhost' identified with mysql_native_password by '123456';
 # 刷新权限 
 flush privileges;

猜你喜欢

转载自blog.csdn.net/qq_40523572/article/details/83016334