美文网首页
CenterOS7安装mysql8.0

CenterOS7安装mysql8.0

作者: 澹台琉璃 | 来源:发表于2021-03-27 22:23 被阅读0次

    1.先删除之前安装的mysql

    通过 rpm -qa | grep mariadbrpm -qa | grep mysql 命令查看 mariadb 和mysql 的安装包
    rpm -e 包名删除所有的安装包

    image.png

    2.从官网获取下载链接

    如图选择版本, 点击Download


    image.png

    右键点击No thanks, 复制链接


    image.png

    3. 下载mysql安装包

    1.创建mysql目录 mkdir /usr/local/mysql
    2.进入刚才创建的目录cd /usr/local/mysql
    3.下载文件 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar

    4.安装mysql

    1. tar -xvf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar解压tar包
      2.安装common, libs, client, server
      rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm --nodeps --force
      rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm --nodeps --force
      rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm --nodeps --force
      rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm --nodeps --force
      3.查看刚才安装的包rpm -qa | grep mysql
      image.png
      4.初始化数据库相关配置
      mysqld --initialize
      chown mysql:mysql /var/lib/mysql -R
      systemctl start mysqld.service
      systemctl enable mysqld

    5.查看随机生成的密码cat /var/log/mysqld.log | grep password

    image.png

    6.修改密码

    mysql -uroot -p进入数据库, 输入刚才看到的密码
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'; 修改密码
    exit退出mysql, 使用新密码重新登录

    7. 设置数据库允许远程连接

    mysql -u root -p
    use mysql;
    select host, user, authentication_string, plugin from user;
    // 允许远程主机连接
    update mysql.user set host='%' where user='root';
    // 修改加密方式
    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
    // 刷新权限
    FLUSH PRIVILEGES;
    
    // 开启系统防火墙
    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    firewall-cmd --reload 
    
    // 配置文件解决sql_mode 'only_full_group_by' 报错
    [mysqld]
    user=mysql
    default-storage-engine=INNODB
    character-set-server=utf8
    default_authentication_plugin=mysql_native_password
    sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8
    

    相关文章

      网友评论

          本文标题:CenterOS7安装mysql8.0

          本文链接:https://www.haomeiwen.com/subject/pcquhltx.html