Linux系统CentOS-7下MySQL-5.7版本安装详细步骤

MySQL5.7版本在CentOS系统安装
  1. 安装需要root权限

  2. 配置yum仓库

    # 更新密钥
    rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
    
    # 安装Mysql yum库
    rpm -Uvh http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
    
  3. 使用yum安装MySQL

    # yum安装Mysql
    yum -y install mysql-community-server
    
  4. 启动MySQL并配置开机自启

    systemctl start mysqld		# 启动
    systemctl enable mysqld		# 开机自启
    
  5. 检查MySQL运行状态

    systemctl status mysqld
    
  6. 获取MySQL的初始密码

    # 通过grep命令,在/var/log/mysqld.log文件中,过滤temporary password关键字,得到初始密码
    grep 'temporary password' /var/log/mysqld.log
    
  7. 登录MySQL

    mysql -uroot -p
    
  8. 降低MySQL的密码安全级别

    set global validate_password_policy=LOW; # 密码安全级别低
    set global validate_password_length=4;	 # 密码长度最低4位即可
    
  9. 修改root用户密码

    ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
    
  10. 授权root远程登录

    # 授权root远程登录
    grant all privileges on *.* to root@"IP地址" identified by '密码' with grant option;  
    
    # 刷新权限,生效
    flush privileges;
    
  11. 退出MySQL

    # 退出命令
    exit
    
    # 或者通过快捷键退出:ctrl + d
    
  12. 检查端口

    netstat -anp | grep 3306
    

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