Centos 7安装mysql 8.0

  1. 卸载mysql

    # 检查是否安装mysql
    rpm -qa | grep mysql 
    # 卸载mysql
    yum remove mysql-xxx-xxx-
    rpm -e mysql---
    # 文件夹
    find / -name mysql
    # 删除
    rm -rf /var/lib/mysql
    
    # 删除mariadb
    rpm -pa | grep mariadb
    # 删除
    rpm -e mariadb-libs-5.5.56
    # 如果失败,强制删除
    rpm -e --nodeps mariadb-libs-5.5.56-2
    
  2. 下载mysql yum包
    http://dev.mysql.com/downloads/repo/yum/

  3. 安装yum包

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

    yum install  -y  mysql-community-server
    
    # 如果报错:"Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022"
    # rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
    

    注意:
    如果需要启动前提前修改配置项,或者自定义数据库存储路径,请参考:
    https://blog.csdn.net/qq_40523572/article/details/109517630
    如果有权限控制,请注意以下文件夹的权限
    /var/log
    /var/lib 或其他mysql的数据库目录
    /var/run
    /usr/sbin

  5. 基础my.cnf配置

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
    # sql mode
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
    # set table name mode, must before db init, else start with error
    lower_case_table_names=1
    
    character-set-server=UTF8MB4
    
    [mysql]
    default-character-set=UTF8MB4
    
    [client]
    port=3306
    socket=/var/lib/mysql/mysql.sock
    default-character-set=UTF8MB4
    
    
  6. 启动mysql

    service mysqld start
    
    # 如果报错,请查看/var/log/mysqld.log
    # 如果权限错误,除了修改文件夹的权限之外,还要注意SELINUX的权限
    # 临时关闭:setenforce 0 
    # 永久关闭需要修改配置文件,重启机器:
    # 修改/etc/selinux/config 文件
    # 将SELINUX=enforcing改为SELINUX=disabled
    
  7. 查看mysql的状态

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

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

    在这里插入图片描述

  9. 登录并修改密码

    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;
    
  10. 创建远程登录账户并授权远程登录

    create user  'admin'@'%'  identified by '123456';
    grant all on  *.*  to  'admin'@'%';
    flush privileges;
    
  11. 远程连接报错相关
    mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之后,加密规则是caching_sha2_password。

     # 修改加密规则
     alter user 'admin'@'%' identified by '123456' password expire never;
     # 更新用户密码
     alter user 'admin'@'%' identified with mysql_native_password by '123456';
     # 刷新权限 
     flush privileges;
    
  12. 查看字符集

    登录mysql查看:
    SHOW VARIABLES LIKE 'character%' 
    
  13. 开放防火墙

    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    firewall-cmd --reload
    firewall-cmd --list-ports
    
  14. 开机自启动

    chkconfig --levels 235 mysqld on
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值