CentOS7安装MySQL(亲测版)

Myth丶恋晨 2024-04-01 18:59 163阅读 0赞

1 Yum Repository下载安装包文件

  1. [root@localhost home]# wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

2 使用yum安装mysql

  1. yum install mysql-server

执行后报错,官方5.7版本默认没有GPG key, 需要在上述命令上 添加 —nogpgcheck 禁掉GPG验证检查

  1. The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
  2. Check that the correct key URLs are configured for this repository.
  3. Failing package is: mysql-community-client-5.7.40-1.el7.x86_64
  4. GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

执行命令

  1. yum install mysql-server --nogpgcheck

3.安装完成后启动MYSQL服务

  1. systemctl start mysqld.service

查看一下运行状态

  1. systemctl status mysqld.service

在这里插入图片描述

  1. 运行成功后查看一下root用户的临时密码

    grep “password” /var/log/mysqld.log

5.使用临时密码进入mysql

  1. mysql -uroot -p

6.修改一下root用户的密码

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

注意如果密码设置不符合策略要求可根据自身情况修改密码或者策略
*如果不需要下面的代码可忽略
(1)修改validate_password_policy参数值为0(1为开启复杂策略)

  1. set global validate_password_policy=0;

(2)修改validate_password_length参数值为1

  1. set global validate_password_length=1;

(3)在执行修改密码操作

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

7.开启远程访问
这里的’%’可替换成具体的ip地址,我这里是测试环境就开启的所有,’password’替换成自己设置的密码

  1. grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;

8.刷新

  1. flush privileges;

测试一下远程连接 OK
(如果是云服务器安全组开一下端口即可)
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,163人围观)

还没有评论,来说两句吧...

相关阅读