• 国内镜像源 centos7 安装 MySQL8.0,并配置远程登录


    国内镜像源

    https://mirror.tuna.tsinghua.edu.cn/help/mysql/
    
    • 1

    新建 /etc/yum.repos.d/mysql-community.repo,内容如下:

    注:mysql-8.0, mysql-connectorsmysql-toolsRHEL 7/8上还提供了aarch64版本。

    [mysql-connectors-community]
    name=MySQL Connectors Community
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
    
    [mysql-tools-community]
    name=MySQL Tools Community
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
    
    [mysql-5.6-community]
    name=MySQL 5.6 Community Server
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
    
    [mysql-5.7-community]
    name=MySQL 5.7 Community Server
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
    
    [mysql-8.0-community]
    name=MySQL 8.0 Community Server
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    或者,替换

    sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
             -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
             -i.bak \
             /etc/yum.repos.d/CentOS-*.repo
    
    • 1
    • 2
    • 3
    • 4

    重建缓存

    yum clean all && yum makecache
    
    • 1

    如果不使用国内镜像源那么配置如下

    如果配置了,镜像源,可以略过本步骤
    https://dev.mysql.com/downloads/repo/yum/

    wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
    
    • 1
    yum install  mysql80-community-release-el7-7.noarch.rpm
    
    • 1

    安装 MySQL

    yum install mysql-community-server --nogpgcheck -y
    
    • 1

    设置开机并启动mysql

    systemctl enable mysqld --now
    
    • 1

    查看安装后 root 初始密码

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

    修改root密码

    输入如下命令后,数据上面的到的密码

    mysql -uroot -p
    
    • 1
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'A.com.123456789';
    
    • 1

    A.com.123456789 即 新密码

    mysql8 创建用户

    先登陆

    mysql -uroot -p
    
    • 1

    执行命令

    create user 'fox'@'%' identified by '999999';
    
    • 1

    999999 即 新密码

    fox 用户授权(全部权限)

    grant all privileges on *.* to 'fox'@'%';
    # 刷新权限
    flush privileges;
    
    • 1
    • 2
    • 3

    创建库名为 fox 的库

    CREATE DATABASE IF NOT EXISTS fox \
    CHARACTER SET utf8mb4 \
    COLLATE utf8mb4_general_ci ;
    
    • 1
    • 2
    • 3

    utf8mb4_bin: 区分大小写的,也区分e和é类字符的
    utf8mb4_genera_ci: 不区分大小写的,也不区分e和é类字符

    开启远程可登陆

    修改配置

    vim /etc/my.cnf
    
    • 1

    [mysql]下面加入

    bind-address=0.0.0.0
    
    • 1

    如果已经存在bind-address,那么把它改为和上面一样

    重启mysql

    systemctl restart mysqld
    
    • 1

    有的centos7 会开启防火墙

    firewall

    查看防火墙状态

    firewall-cmd --state
    
    • 1

    开启端口

    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    
    • 1

    应用

    firewall-cmd --reload
    
    • 1

    iptables

    iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
    
    • 1

    命令

    设置开机并启动

    systemctl enable mysqld --now
    
    • 1

    启动

    systemctl start mysqld
    
    • 1

    关闭

    systemctl stop mysqld
    
    • 1

    重启

    systemctl restart mysqld
    
    • 1

    状态

    systemctl status mysqld
    
    • 1
  • 相关阅读:
    697226-52-1, 细胞穿膜肽TAT-amide
    海量数据去重的Hash与BloomFilter学习笔记
    js双向绑定
    JS操作字符串面试题系列(3)-每天做5题
    kafka-consumer-offset位移
    java毕业设计某服装店购物网站源码+lw文档+mybatis+系统+mysql数据库+调试
    【Python 千题 —— 基础篇】多行输出
    Java多线程之8锁案例
    【解决】自定义conda环境安装位置,三种解决方法
    【oj刷题记】【1366】【KMP字符串模式匹配算法】【next【】数组的细致研究】【探讨ne[]数组0,1开头和-1,0开头的区别】
  • 原文地址:https://blog.csdn.net/wljk506/article/details/126717857