首页 / MYSQL / “在MySQL中识别’密码’”
“在MySQL中识别’密码’”
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了“在MySQL中识别’密码’”,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1898字,纯文字阅读大概需要3分钟。
内容图文
![“在MySQL中识别’密码’”](/upload/InfoBanner/zyjiaocheng/888/4d92c77115134a4b973347eacde553c3.jpg)
我经常在许多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中识别’密码’”全部内容,希望文章能够帮你解决“在MySQL中识别’密码’”所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。