天天看点

centos7 安装mysql5.7, wget,修改5.7密码规则(mysql5.7.27)

如果系统未安装的情况下:

1.下载 mysql57-community-release-el7-8.noarch.rpm 的 YUM 源:

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
           

(如果没有wget,有就不执行)

yum -y install wget 
           

2.安装 mysql57-community-release-el7-8.noarch.rpm:

rpm -ivh mysql57-community-release-el7-8.noarch.rpm
           

安装完后,得到如下两个包:

mysql-community.repo 

mysql-community-source.repo

3.安装 MySQL,出现提示的话,一路 Y 到底

yum install mysql-server
           

4.安装完毕后,启动mysql

systemctl start mysqld
           

5.然后在  /var/log/mysqld.log 文件中会自动生成一个随机的密码,我们需要先取得这个随机密码,以用于登录 MySQL 服务端:

cat /var/log/mysqld.log | grep password
           

将会返回如下内容,末尾字符串就是密码,把它复制下来:

2019-10-12T14:40:15.759312Z 1 [Note] A temporary password is generated for [email protected]: srPy7g&:Bh6D
2019-10-12T14:40:51.090059Z 2 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2019-10-12T14:40:59.727282Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2019-10-12T14:41:10.394524Z 4 [Note] Access denied for user 'root'@'localhost' (using password: YES)
           

第一行最后的是你的密码,

6.登录到 MySQL 服务端并更新用户 root 的密码:

注意:由于 MySQL5.7 采用了密码强度验证插件 validate_password,故此我们需要设置一个有一定强度的密码;

mysql -u root -p
           

然后输入密码,我的密码是srPy7g&:Bh6D

然后更改密码

alter user 'root'@'localhost' identified by '您的密码';
           

如果密码出现,

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'the manual that corresponds to your MySQL server version for the right syntax to' at line 1
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
           

这个是因为validate_password_policy的值有关。

默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。

必须修改两个全局参数:

首先,修改validate_password_policy参数的值

set global validate_password_policy=0;
           

Query OK, 0 rows affected (0.00 sec)(成功)

validate_password_length(密码长度,可改可不改)参数默认为8,我们修改为6

set global validate_password_length=6;
           

Query OK, 0 rows affected (0.00 sec)(成功)

之后再更改密码

alter user 'root'@'localhost' identified by '您的密码';
           

如果navicat报错1130就是下面这个访问权限未设置

7.设置mysql在任意ip下可以被访问或者本地被访问:

本地:

grant all privileges on *.* to root@"localhost" identified by "你的密码";
           

任意:

grant all privileges on *.* to root@"%" identified by "你的密码";
           

刷新并应用

flush privileges;
           

退出

exit