CentOS7安装MySQL(亲测版)

1 Yum Repository下载安装包文件

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

2 使用yum安装mysql

yum install mysql-server

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

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-client-5.7.40-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

执行命令

yum install mysql-server --nogpgcheck

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

systemctl start  mysqld.service

查看一下运行状态

systemctl status mysqld.service

在这里插入图片描述
4. 运行成功后查看一下root用户的临时密码

grep "password" /var/log/mysqld.log

5.使用临时密码进入mysql

mysql -uroot -p

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

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

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

set global validate_password_policy=0;

(2)修改validate_password_length参数值为1

set global validate_password_length=1;

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

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

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

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

8.刷新

flush privileges; 

测试一下远程连接 OK
(如果是云服务器安全组开一下端口即可)
CentOS7安装MySQL(亲测版)_第1张图片

你可能感兴趣的:(mysql,数据库,linux)