mysql5.7密码策略及修改技巧

MySQL5.7为root用户随机生成了一个密码,打印在error_log中,关于error_log的位置,若是安装的是RPM包,则默认是 /var/log/mysqld.log 。
因而咱们能够在mysqld.log中找到初始密码串:mysql

.#cat /var/log/mysqld.log | grep passwordweb

用初始密码串登录便可
.#mysql -u root -p”password”sql

根据官方文档能够发现策略
必须知足:数字、小写字母、大写字母 、特殊字符、长度至少8位安全

修改密码复杂度:ide

法一:
在/etc/my.cnf配置文件中增长
[mysqld]
validate_password=off #关闭密码复杂度验证
default_password_lifetime=0 #设置密码不会过时svg

而后#service mysqld restart或者#systemctl restart mysqld.service重启mysqldrest

法二:
更改密码策略为LOWxml

set global validate_password_policy=0;ip

更改密码长度文档

set global validate_password_length=0;

如此便可随意设置密码:

update mysql.user set authentic
ation_string=password(‘123456’) where user=’root’ and Host = ‘localhost’;
或者
set password for ‘root’@’localhost’=password(‘123456’);

固然,咱们还有一种办法,就是在最最开始的时候,不设置初始密码:
只须要在初始化时指定–initialize-insecure便可,好比:
mysqld –initialize-insecure –datadir=/var/lib/mysql –basedir=/usr –user=mysql

数据用户操做

select Host,User,Password from mysql.user; #查询全部用户
create user test identified by ‘123456’; #建立用户及密码
grant all privileges on . to ‘test’@’%’identified by ‘123456’ with grant option;
.#受权全部地址均可以访问

all表明接受全部操做,好比 select,insert,delete….; . 表明全部库下面的全部表;% 表明这个用户容许从任何地方登陆;为了安全期间,这个%能够替换为你容许的ip地址;

而后刷新mysql用户权限相关表;

flush privileges ;

参考:https://www.jianshu.com/p/5779aa264840