zoukankan      html  css  js  c++  java
  • mysql5.7密码设置

    mysql5.7版本引入了强制更改密码的举措,只能吐槽一句,shit!mysql5.7安装
    安装完mysql之后,mysql已经随机指定了一个初始化密码,可以在mysql的错误日志中找到初始化密码:

    cat /var/log/mysqld.log  | grep password
    2018-07-05T05:02:46.258821Z 0 [ERROR] unknown variable 'validate_password_policy=0'
    2018-07-05T05:05:04.538912Z 1 [Note] A temporary password is generated for root@localhost: 9kkYpe)x>>2V
    2018-07-05T05:05:09.218798Z 2 [Note] Access denied for user 'UNKNOWN_MYSQL_USER'@'localhost' (using password: NO)

    根据临时密码进入mysql的交互界面,进行任何操作都会报如下错误提示:

    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    
    进入之后随便执行一条语句,会发现系统提示你必须使用alter user语句更改密码,(oracle为了数据库的安全真是操碎了心)
    在试了n次密码之后,仍然报如下错误
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    命运多舛,时运不济啊!
    mysql> alter user "root"@"localhost" identified by "123qwE#!";  #密码含有 数字,大写字母,小写字母,特殊字符
    Query OK, 0 rows affected (0.01 sec)
    
    mysql>

    但有时候我们临时测试的时候不需要这么复杂的密码,这时候可以看如下设置。

    若想快速的使用mysql 简单的 密码请按如下设置,直接在交互行执行:
    mysql> set global validate_password_policy=0;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> set global validate_password_length=4;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> set password=password("123456");
    Query OK, 0 rows affected, 1 warning (0.01 sec)
    
    这样就可以正常使用账户和密码了。

    详解了解一下这几个参数

    查看控制密码设置的几个参数
    mysql> show variables like "validate_password%";
    +--------------------------------------+-------+
    | Variable_name                        | Value |
    +--------------------------------------+-------+
    | validate_password_check_user_name    | OFF   |
    | validate_password_dictionary_file    |       |
    | validate_password_length             | 8     |
    | validate_password_mixed_case_count   | 1     |
    | validate_password_number_count       | 1     |
    | validate_password_policy             | LOW   |
    | validate_password_special_char_count | 1     |
    +--------------------------------------+-------+
    7 rows in set (0.01 sec)
    
    密码安全策略:validate_password_policy
    策略              检查规则
    0 or LOW            Length
    1 or MEDIUM         Length; numeric, lowercase/uppercase, and special characters
    2 or STRONG         Length; numeric, lowercase/uppercase, and special characters; dictionary file
    
    validate_password_dictionary_file:    密码策略文件,需要安全策略参数为strong或2.
    validate_password_length:             密码长度, 默认是8
    validate_password_mixed_case_count:   密码中大小写字母数量至少为1
    validate_password_number_count:       密码中数字的数量至少为1
    validate_password_special_char_count: 密码中特殊字符的个数至少为1 
    validate_password_check_user_nam:     检查用户名 
    
    修改策略的时候,可以直接用set global varname参数修改。

    需要注意的是:

    但是若在错误日志中找不到初始化密码,就得不走寻常路了使用skip-grant-tables参数。
    只说明方法,不会具体操作:
    在配置文件中加入skip-grant-tables参数,然后重新启动mysql服务,这时候不需要密码即可进入交互界面。
    然后 执行 update mysql.user set authentication_string=password('123456') where user='root';(需要注意的是:mysql57版本中user表的password字段已经更新为authentication_string字段。)语句更改root用户密码,其余的set语句好像不能执行。

    更改成功之后,注释掉配置文件中的skip-grant-tables参数,重新启动mysql,然后就可以使用密码进入交互界面。

  • 相关阅读:
    http协议详解(经典版)
    Sql语句清理日志文件
    Case when用法
    Sql Server 语句美化工具,SQL Pretty Printer Add-In for SSMS
    Ext.Net保存前判断GridPanel中必填项是否为空
    JavaScript中判断对象的值是否为undefined、null
    Your project specifies TypeScriptToolsVersion 3.1, but a matching compiler was not found. The latest available TypeScript compiler will be used (3.3). To remove this warning, install the TypeScript 3.
    gist.github.com 被墙无法访问解决办法
    VSCode 多标签打开文件
    VSCode安装与配置Eslint
  • 原文地址:https://www.cnblogs.com/wxzhe/p/9594543.html
Copyright © 2011-2022 走看看