文章目录

centos8 下安装mysql5.7

由 xiao 发布
  • 查看之前已安装的 mysql
    rpm -qa |grep mysql
    
    如果不为空,则删除,有多个则删除多个
    eg: rpm -e  mysql-community-server-5.7.30-1.el7.x86_64
    
  • 安装 wget,有则无需安装
    yum install wget
  • 下载 mysqlrpm
    wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  • 安装 mysqlrpm
    rpm -ivh mysql80-community-release-el7-3.noarch.rpm
  • 修改 repo文件
    cd /etc/yum.repos.d/
    vim mysql-community.repo
    
    将 [mysql57-community] 下的 enabled 设置为1,表示打开5.7
    将 [mysql80-community] 下的 enabled 设置为0,表示关闭8.0
  • 安装 mysql
    yum -y install mysql-community-server
    
    如执行上面命令报错,则先执行
    
    yum module disable mysql
  • 检测 mysql 是否安装成功
    mysql --version
  • 启动 mysql
    systemctl start mysqld.service  or systemctl start mysqld   启动mysql
    systemctl stop mysqld.service  or systemctl stop mysqld     停止mysql
    systemctl mysql mysqld.service  重启mysql
    
    systemctl status mysqld.service   查看mysql状态
    
  • 修改 mysql相关配置
    # 获取mysql临时密码
    grep 'temporary password' /var/log/mysqld.log
    
    # 登录 
    mysql -uroot -p 
    
    # 修改密码 密码规则:必须包含 大小写字母、数字、特殊符号
    set password for 'root'@'localhost'=password('Qa2020@0825!');
    
    # 刷新到内存
    flush privileges
    
    # 添加远程登录用户
    GRANT ALL PRIVILEGES ON *.* TO 'xiao'@'%' IDENTIFIED BY 'Xiao2020@0825!' WITH GRANT OPTION
    
    or 
    
    use mysql;
    UPDATE user SET Host='%' WHERE User='root';
    
    flush privileges  #刷新
     
  • 设置默认编码为 utf-8
    vim /etc/my.cnf 
    # 末尾添加
    
    [mysqld]
    character-set-server=utf8
    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8
    
    重启mysql 并进入到mysql
    
    show variables like 'character%';
  • centos 防火墙相关
    # 查看防火墙端口是否开放
    firewall-cmd --query-port=3306/tcp
    
    # 开放防火墙端口3306
    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    
    # 关闭防火墙
    systemctl stop firewalld
    
    # 打开防火墙
    systemctl start firewalld
    
    # 开放一段端口
    firewall-cmd --zone=public --add-port=40000-45000/tcp --permanent
    
    # 查看开放的端口列表
    firewall-cmd --zone=public --list-ports
    
    

暂无评论

发表评论