mysql初始化密码问题

    技术2022-07-10  107

    查看mysql初始化密码

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

    登录并修改密码

    `mysql -uroot -p` alter user 'root'@'localhost' identified by 'root';

    不然会报如下错误:

    mysql> use mysql; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    如果设置一个简单的测试密码的话,比如设置为123456,会提示这个错误,报错的意思就是你的密码不符合要求

    mysql> alter user 'root'@'localhost' identified by '123456'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    这个其实与validate_password_policy的值有关。

    那我们先看看数据库当前的密码策略是啥

    mysql root@localhost:(none)> show VARIABLES like "%password%"

    默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。 设置简单密码 首先,修改validate_password_policy参数的值和validate_password_length(密码长度)

    mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec) mysql> set global validate_password_length=0; Query OK, 0 rows affected (0.00 sec)

    完成之后再次执行修改密码语句即可成功

    mysql> alter user 'root'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.00 sec)
    Processed: 0.053, SQL: 9