Cane's Blog

Cane

【Problem】MySQL常遇问题汇总

20
2019-12-24

设置简单密码

  1. 查看密码策略

    SHOW VARIABLES LIKE 'validate_password%';

    20180314150646341.png

  2. 修改密码强度等级

    set global validate_password_policy=LOW;

    20180314150646341-1.png

  3. 修改密码长度限制

    set global validate_password_length=6;

    20180314150646341-2.png

  4. 修改密码

    ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
  5. 补充

    密码的长度最小值为 4 ,由 大/小写字母各一个 + 阿拉伯数字一个 + 特殊字符一个,只要设置密码的长度小于 3 ,都将自动设值为 4

    20180314150646341-4.png

    关于 mysql 密码策略相关参数;
    validate_password_length 固定密码的总长度;
    validate_password_dictionary_file 指定密码验证的文件路径;
    validate_password_mixed_case_count 整个密码中至少要包含大/小写字母的总个数;
    validate_password_number_count 整个密码中至少要包含阿拉伯数字的个数;
    validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;
    validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

    关于 validate_password_policy 的取值:
    0/LOW:只验证长度;
    1/MEDIUM:验证长度、数字、大小写、特殊字符;
    2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;

开启远程连接

  1. 登陆 mysql 数据库,查看 user 表

    mysql> use mysql;
    
    mysql> select host,user,password from user;
    
    +--------------+------+-------------------------------------------+
    | host         | user | password                                  |
    +--------------+------+-------------------------------------------+
    | localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    | 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    +--------------+------+-------------------------------------------+

    host 字段表示允许登录的主机,其值可以用 IP,也可用主机名。

  2. 添加远程主机并刷新权限

    mysql> grant all privileges  on *.* to root@'%' identified by "password";
    
    mysql> flush privileges;
    
    mysql> select host,user,password from user;
    +--------------+------+-------------------------------------------+
    | host         | user | password                                  |
    +--------------+------+-------------------------------------------+
    | localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    | 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    | %            | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
    +--------------+------+-------------------------------------------+