ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

“在MySQL中识别’密码’”

2019-10-05 17:14:43  阅读:240  来源: 互联网

标签:mysql privileges grant


我经常在许多MySQL教程中看到人们在用户创建期间使用命令IDENTIFIED BY’password’并授予他权限.

例如:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';

我尝试使用没有IDENTIFIED BY的GRANT,它的工作原理.
有人能解释一下为什么它会被使用两次吗?特定权限可以有其他密码吗?

解决方法:

GRANT用于向用户添加权限.令人困惑的是,它还能够创建用户并更改其密码.不推荐使用此功能,不应使用此功能.

如果您将GRANT与IDENTIFIED一起使用,则可以更改用户密码:

When IDENTIFIED is present and you have the global grant privilege (GRANT OPTION), any password specified becomes the new password for the account, even if the account exists and already has a password. Without IDENTIFIED, the account password remains unchanged.

As of MySQL 5.7.2, if the account already exists, IDENTIFIED WITH is prohibited because it is intended only for use when creating new accounts.

此外,如果用户不存在,GRANT可以创建用户:

If an account named in a GRANT statement does not exist, the action taken depends on the NO_AUTO_CREATE_USER SQL mode:

  • If NO_AUTO_CREATE_USER is not enabled, GRANT creates the account. This is very insecure unless you specify a nonempty password using IDENTIFIED BY.
  • If NO_AUTO_CREATE_USER is enabled, GRANT fails and does not create the account, unless you specify a nonempty password using IDENTIFIED BY or name an authentication plugin using IDENTIFIED WITH.

Use of GRANT to define account authentication characteristics is deprecated as of MySQL 5.7.6. Instead, establish or change authentication characteristics using CREATE USER or ALTER USER. This GRANT capability will be removed in a future MySQL release.

https://dev.mysql.com/doc/refman/5.7/en/grant.html

总之,使用CREATE创建用户,并使用GRANT添加权限:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost'; 

标签:mysql,privileges,grant
来源: https://codeday.me/bug/20191005/1857049.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有