• CentOS8安装Mysql5.7


    检查是否安装mysql

    [root@iZ2ze8crquorxf6c7l0eluZ ~]# rpm -qa |grep mysql
    [root@iZ2ze8crquorxf6c7l0eluZ ~]# 
    

    没有任何返回代表没有安装mysql

    安装mysql

    1、安装wget(wget是Linux中的一个下载文件的工具)

    [root@iZ2ze8crquorxf6c7l0eluZ ~]# yum install wget
    Last metadata expiration check: 1:30:08 ago on Mon 17 Aug 2020 11:35:44 AM CST.
    Package wget-1.19.5-8.el8_1.1.x86_64 is already installed.
    Dependencies resolved.
    Nothing to do.
    Complete!
    

    这个是已经安装成功的提示
    2、 下载mysql的rpm

    [root@iZ2ze8crquorxf6c7l0eluZ ~]# wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    --2020-08-17 13:21:05--  http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
    Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
    HTTP request sent, awaiting response... 301 Moved Permanently
    Location: https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm [following]
    --2020-08-17 13:21:06--  https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
    Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
    HTTP request sent, awaiting response... 302 Found
    Location: https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [following]
    --2020-08-17 13:21:11--  https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
    Resolving repo.mysql.com (repo.mysql.com)... 23.211.97.88
    Connecting to repo.mysql.com (repo.mysql.com)|23.211.97.88|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 26024 (25K) [application/x-redhat-package-manager]
    Saving to: ‘mysql80-community-release-el7-3.noarch.rpm’
    
    mysql80-community-release-el7-3.noarc 100%[======================================================================>]  25.41K  --.-KB/s    in 0.1s    
    
    2020-08-17 13:21:11 (229 KB/s) - ‘mysql80-community-release-el7-3.noarch.rpm’ saved [26024/26024]
    
    

    3、安装mysql的rpm

    [root@iZ2ze8crquorxf6c7l0eluZ ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
    warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Verifying...                          ################################# [100%]
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql80-community-release-el7-3  ################################# [100%]
    

    /etc/yum.repos.d/目录下生成两个文件
    mysql-community.repo和mysql-community-source.repo
    4、修改repo文件

    [root@iZ2ze8crquorxf6c7l0eluZ ~]# cd /etc/yum.repos.d/
    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# vim mysql-community.repo
    

    在这里插入图片描述
    将5.7的enable改为1,8.0的enable改为0
    在这里插入图片描述
    i进入修改模式-》修改-》esc退出修改模式-》:wq保存并退出
    5、安装Mysql

    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# yum -y install mysql-community-server
    

    如果报错Error: Unable to find a match: mysql-community-server
    先执行下面语句再安装

    yum module disable mysql
    

    6、查看Mysql版本

    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# mysql --version
    mysql  Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using  EditLine wrapper
    

    7、启动Mysql并查看Mysql状态

    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: inactive (dead)
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# systemctl start mysqld.service
    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Mon 2020-08-17 14:06:31 CST; 5s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 30074 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 30018 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 30077 (mysqld)
        Tasks: 27 (limit: 11516)
       Memory: 342.9M
       CGroup: /system.slice/mysqld.service
               └─30077 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    Aug 17 14:05:56 iZ2ze8crquorxf6c7l0eluZ systemd[1]: Starting MySQL Server...
    
    

    8、查看mysql临时密码

    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# grep 'temporary password' /var/log/mysqld.log
    2020-08-17T06:06:28.781067Z 1 [Note] A temporary password is generated for root@localhost: lF%_XqVtO5XW
    
    

    9、登录mysql

    [root@iZ2ze8crquorxf6c7l0eluZ yum.repos.d]# mysql -uroot -plF%_XqVtO5XW
    

    9、修改mysql登录密码

    set global validate_password_policy=LOW;
    set global validate_password_length=4;
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('输入新密码');
    

    修改Mysql8.0密码不满足当前策略要求解决方 随便找的
    先修改密码策略然后设置密码,或者设置一个很复杂的密码也行
    10、添加远程访问用户

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
    flush privileges; 
    

    创建了一个可以在任意IP访问的用户

  • 相关阅读:
    阿里巴巴人力资源挖坑 面试技术挑战题
    •••| 卡牌游戏诞生记 |•••
    JavaScript:js-cookie存取
    乘积最大
    最大的算式
    KMP笔记√//找最大子串,前缀自匹配长度
    牛棚回声
    P1027 木瓜地
    P1026 犁田机器人
    P1023 奶牛的锻炼
  • 原文地址:https://www.cnblogs.com/zhangguangxiang/p/14232506.html
Copyright © 2020-2023  润新知