简体   繁体   English

如何在 MySQL 5.7 中创建六个字符的密码

[英]How to create a six character password in MySQL 5.7

I need to create a user with a six character password in new MySQL on my mac.我需要在我的 mac 上的新 MySQL 中创建一个具有六个字符密码的用户。 I know that the lowest setting in 5.7 will allows only eight characters.我知道 5.7 中的最低设置只允许八个字符。 Is there any way to go around that?有什么办法可以解决这个问题吗?

I type in CREATE USER 'newsier'@'localhost' IDENTIFIED BY 'special'我输入CREATE USER 'newsier'@'localhost' IDENTIFIED BY 'special'

It outputs the error它输出错误

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

First you login with mysql -u root -p and check the current policy rules by:首先,您使用mysql -u root -p登录并通过以下方式检查当前策略规则:

# SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_dictionary_file    |        |
| validate_password_length             | 5      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+

Then you can change any of the above variables at your will:然后您可以随意更改上述任何变量:

# SET GLOBAL validate_password_length = 5;
# SET GLOBAL validate_password_number_count = 0;
# SET GLOBAL validate_password_mixed_case_count = 0;
# SET GLOBAL validate_password_special_char_count = 0;

Finally you can create a database and a user accessing it with a simpler password:最后,您可以创建一个数据库和一个使用更简单密码访问它的用户:

# CREATE DATABASE test1;
# GRANT ALL PRIVILEGES ON test1.* TO user1@localhost IDENTIFIED BY "pass1";
# FLUSH PRIVILEGES;

After that you can login with mysql -u user1 -p test1 using password pass1之后,您可以使用密码pass1使用mysql -u user1 -p test1登录

You are using the password validation plugin .您正在使用密码验证插件 By default it only allows 8 characters and longer passwords.默认情况下,它只允许 8 个字符和更长的密码。 Because it can't check the value of a hash, @RiggsFolly is correct that pre-hashing the password will work.因为它无法检查散列的值,@RiggsFolly 是正确的,预散列密码将起作用。

However, if you want to change the options , you'll need to set the value of the validate_password_length system variable.但是,如果要更改 options ,则需要设置validate_password_length系统变量的值。 You can do this in the configuration file or:您可以在配置文件中执行此操作或:

SET GLOBAL validate_password_length=6;

MySQL 5.7+ by default haves a Password validation system . MySQL 5.7+默认有一个密码验证系统 In case if you don't want to go strictly with the policy and need to assign your own then just disable the password validation and restart mysqld process.如果您不想严格执行该策略并需要分配您自己的策略,则只需禁用密码验证并重新启动mysqld进程。

Edit my.cnf file :编辑my.cnf文件:

vi /etc/my.cnf

in [mysqld][mysqld]

validate-password=off

Save the file and then restart the process保存文件,然后重新启动该过程

sudo service mysqld restart
or
systemctl restart mysqld

and then change the Root Password using the following and follow the steps it won't throw exception for the Root Password.然后使用以下方法更改 Root 密码,并按照不会为 Root 密码引发异常的步骤进行操作。

mysql_secure_installation
or
/usr/bin/mysql_secure_installation

If you are doing installation for the first time and want to know the temporary password then use the following to find the first time password :如果您是第一次安装并想知道临时密码,请使用以下方法查找首次密码

 grep 'temporary password' /var/log/mysqld.log

Let me know your comments on the same, in the below comment box.在下面的评论框中让我知道您对此的评论。

It's possible to entirely disable the password "plugin" that seems overly strict by running the following: uninstall plugin validate_password通过运行以下命令,可以完全禁用看起来过于严格的密码“插件”: uninstall plugin validate_password

Should you need it again you can turn it back on via: INSTALL PLUGIN validate_password SONAME 'validate_password.so'如果您再次需要它,您可以通过以下方式重新打开它: INSTALL PLUGIN validate_password SONAME 'validate_password.so'

Optionally, you could disable it, set your password and re-enable it:或者,您可以禁用它,设置密码并重新启用它:

uninstall plugin validate_password;
CREATE USER 'newsier'@'localhost' IDENTIFIED BY 'special';
INSTALL PLUGIN validate_password SONAME 'validate_password.so';

Further reading:进一步阅读:

Check current password policy rules by通过以下方式检查当前密码策略规则

SHOW VARIABLES LIKE 'validate_password%';

Now set new value of those variable:现在设置这些变量的新值:

SET GLOBAL validate_password_length = 6 ; // that you like
SET GLOBAL validate_password_policy = LOW ;

I believe you can get round it by using a pre hashed password like this :-我相信您可以通过使用这样的预散列密码来绕过它:-

CREATE USER 'newsier'@'localhost' IDENTIFIED WITH mysql_native_password
       AS '*0D3CED9BEC10A777AEC23CCC353A8C08A633045E';

But that does mean you need to hash special correctly before this will actually set a password that you can then use the plain text version of.但这确实意味着您需要正确散列special ,然后才能实际设置密码,然后您可以使用纯文本版本。

这可能有帮助:

GRANT ALL ON wordpress.* TO 'user'@'localhost' IDENTIFIED WITH mysql_native_password AS'yourpassword';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM