我想在MySQL中创建一个新用户,语法如下:

create user 'demo'@'localhost' identified by 'password';

但是它会返回一个错误:

您的密码不符合当前策略要求。

我试过很多密码,但都没用。我该如何解决这个问题?


当前回答

执行sudo mysql_secure_installation. sh命令后。

2 .执行sudo mysql命令,进入“mysql”界面。 运行SELECT user,authentication_string,plugin,host FROM mysql.user;检查root用户是否有插件auth_socket。 然后运行卸载插件validate_password;在运行之前删除特权 this ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

注意:查看这个链接https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04以获得更多帮助

其他回答

执行sudo mysql_secure_installation. sh命令后。

2 .执行sudo mysql命令,进入“mysql”界面。 运行SELECT user,authentication_string,plugin,host FROM mysql.user;检查root用户是否有插件auth_socket。 然后运行卸载插件validate_password;在运行之前删除特权 this ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

注意:查看这个链接https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04以获得更多帮助

如果你不关心密码策略。你可以通过下面的mysql命令将其设置为LOW:

mysql> SET GLOBAL validate_password.length = 4;
mysql> SET GLOBAL validate_password.policy=LOW;

如果你想设置一个空白密码。然后在MySQL客户端运行以下查询:

SET GLOBAL validate_password.check_user_name = No;
SET GLOBAL validate_password.dictionary_file = '';
SET GLOBAL validate_password.length = 0;
SET GLOBAL validate_password.mixed_case_count = 0;
SET GLOBAL validate_password.number_count = 0;
SET GLOBAL validate_password.policy = LOW;
SET GLOBAL validate_password.special_char_count = 0;

输出应该是这样的:

    SHOW VARIABLES LIKE 'validate_password%';

+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password.check_user_name    | ON    |
| validate_password.dictionary_file    |       |
| validate_password.length             | 0     |
| validate_password.mixed_case_count   | 0     |
| validate_password.number_count       | 0     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 0     |
+--------------------------------------+-------+

然后,您可以使用以下查询更新您的空白密码:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
SHOW VARIABLES LIKE 'validate_password%';

mysql> SET GLOBAL validate_password.length = 6;
mysql> SET GLOBAL validate_password.number_count = 0;
mysql> SET GLOBAL validate_password.policy=LOW;
SHOW VARIABLES LIKE 'validate_password%';

对于Laravel用户在MySQL 8.0中遇到此问题。x,添加

'modes'=> [
             'ONLY_FULL_GROUP_BY',
             'STRICT_TRANS_TABLES',
             'NO_ZERO_IN_DATE',
             'NO_ZERO_DATE',
             'ERROR_FOR_DIVISION_BY_ZERO',
             'NO_ENGINE_SUBSTITUTION',
            ],

到你的database.php文件如下所示:

// database.php

    'connections' => [

        'mysql' => [
            'driver'      => 'mysql',
            'host'        => env( 'DB_HOST', '127.0.0.1' ),
            'port'        => env( 'DB_PORT', '3306' ),
            'database'    => env( 'DB_DATABASE', 'forge' ),
            'username'    => env( 'DB_USERNAME', 'forge' ),
            'password'    => env( 'DB_PASSWORD', '' ),
            'unix_socket' => env( 'DB_SOCKET', '' ),
            'charset'     => 'utf8mb4',
            'collation'   => 'utf8mb4_unicode_ci',
            'prefix'      => '',
            'strict'      => true,
            'engine'      => null,
            'modes'       => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],
        ],
    ],

它帮我解决了问题。