centos7安装mysql

  1. 获取MySQL Yum Repository

    点击查看官方最新包

    本次安装5.7使用

    wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
    
  2. 安装源

    yum -y install mysql57-community-release-el7-11.noarch.rpm
    # mysql57-community-release-el7-11.noarch.rpm 替换成上一步自己下载的文件名
    
  3. 查看安装效果

    yum repolist enabled | grep mysql.*
    
  4. 安装mysql-community-server

    yum install -y mysql-community-server
    

    若此处报错

    The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package.
    Check that the correct key URLs are configured for this repository.

    Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
    GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    执行

    rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
    
  5. 启动MySQL服务

    # 启动服务
    systemctl start mysqld.service
    
    # 查看服务状态
    systemctl status mysqld.service
    
  6. 查看初始密码

    grep "password" /var/log/mysqld.log
    
  7. 登录MySQL

    mysql -uroot -p
    #回车后输入密码,输入时是不可见的
    
  8. 修改密码

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxx';
    # xxx就是新密码
    

    注意:

    MySQL默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误

如果要设置简单密码,需要在设置密码后,在sql命令下修改密码规则:

# 设置密码的验证强度等级
set global validate_password_policy=LOW;
# 设置密码长度
set global validate_password_length=6;
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxx';
  1. 授权远程登录

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    # root(授权的用户)
    # 123456(密码)
    # %代表所有IP,此处也可以输入指定IP
    
    # 执行以下命令刷新
    FLUSH PRIVILEGES;
    
  2. 配置自启动

    systemctl enable mysqld
    systemctl daemon-reload
    

你可能感兴趣的:(mysql,linux,centos)