当前位置:网站首页>小白学习MySQL - 不同版本创建用户的些许区别
小白学习MySQL - 不同版本创建用户的些许区别
2022-04-21 15:36:00 【bisal】
MySQL创建用户有很多种方法,例如常规create user,再通过grant,授予权限,还可直接grant连带创建用户和授权一起做了。最近创建过程中,发现不同版本操作有些区别。
MySQL 5.7官方手册,给出了创建用户的操作步骤,
https://dev.mysql.com/doc/refman/5.7/en/grant.html
但实际上,grant带着identified by是可以的,
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.32-log |
+------------+
1 row in set (0.02 sec)
mysql> create user test identified by 'test';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on `mysql`.* to 'test'@'%' identified by 'test';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show grants for 'test'@'%';
+-------------------------------------------------+
| Grants for test@% |
+-------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'%' |
| GRANT ALL PRIVILEGES ON `mysql`.* TO 'test'@'%' |
+-------------------------------------------------+
2 rows in set (0.00 sec)
MySQL 8.0官方手册上,给出的操作步骤基本和5.7是相同的,
https://dev.mysql.com/doc/refman/8.0/en/grant.html
但是执行的时候,grant如果加上identified by,就会提示语法存在错误,
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.23 |
+-----------+
1 row in set (0.00 sec)
mysql> create user test identified by 'test';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on `mysql`.* to 'test'@'%' identified by 'test';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'test'' at line 1
其实这对create user和grant分开执行的场景没什么影响,无非是多个少个identified by的问题,但是如果通过grant将创建用户和授权一起执行的场景,就会有些影响,例如5.7中,可以通过grant达到创建用户和授权的效果,当然,这个受sql_mode中的参数NO_AUTO_CREATE_USER的控制,如果指定了,就是允许如下的操作,
mysql> grant all privileges on `mysql`.* to 'testdb'@'%' identified by 'testdb';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show grants for 'testdb'@'%';
+---------------------------------------------------+
| Grants for testdb@% |
+---------------------------------------------------+
| GRANT USAGE ON *.* TO 'testdb'@'%' |
| GRANT ALL PRIVILEGES ON `mysql`.* TO 'testdb'@'%' |
+---------------------------------------------------+
2 rows in set (0.00 sec)
但是8.0中,这个操作,就会提示错误,
mysql> grant all privileges on `mysql`.* to 'testdb'@'%' identified by 'testdb';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'testdb'' at line 1
这个应该和8.0的特性相关,如文档所说,从8.0.11开始,就删除了sql_mode中NO_AUTO_CREATE_USER参数,
https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html
因此对他来说,这是正常现象。至于设计原因,我猜还是想让用户创建的过程更标准、更加原子性,一个操作,就做一件事,出错的几率,就更可控。
小白学习MySQL,
《小白学习MySQL - varchar类型字段为什么经常定义成255?》
《小白学习MySQL - TIMESTAMP类型字段非空和默认值属性的影响》
《小白学习MySQL - InnoDB支持optimize table?》
《小白学习MySQL - table_open_cache的作用》
《小白学习MySQL - only_full_group_by的校验规则》
《小白学习MySQL - max_allowed_packet》
《小白学习MySQL - mysqldump保证数据一致性的参数差异》
版权声明
本文为[bisal]所创,转载请带上原文链接,感谢
https://cloud.tencent.com/developer/article/1985484
边栏推荐
- 102页新一代数字化转型信息化总体规划方案
- 105页数字孪生城市信息模型CIM平台建设技术方案
- 登录程序2
- Oracle 官宣:腾讯 JDK 18 国内第一!
- Obsidian 自动上传图片到图床——安装PicGo插件并配置
- What conditions need to be met for an app to go online in the app store?
- Site intelligent solution
- ABAQUS loads according to coordinates - analytical field load mapping
- EmlParse:一款超轻量级的批量解析EML格式电子邮件的工具
- 许远东受邀上海管理科技论坛做《LTD数字化经营方法论》分享
猜你喜欢

58页西门子机床行业数字化解决方案

Plug in development practice of a simple annotation Library

左程云 - 大厂刷题班 - 摆砖块

嵌入式驱动模块的加载与卸载

LeetCode 203、移除链表元素

Mysql

LeetCode 1572、矩阵对角线元素的和

无常损失简单解释

How do I log in to the enterprise mailbox? Enterprise mailbox login method

Smart Park Digital financing - Digital enabling operation management platform solution
随机推荐
Spark / Scala - read rcfile & orcfile
Is Baidu cloud disk easy to use or Alibaba cloud disk easy to use?
LeetCode 566、重塑矩阵
105页数字孪生城市信息模型CIM平台建设技术方案
(计数线段树)lintcode中等248 · 统计比给定整数小的数的个数
MySQL8. 0 correct password change posture
Huawei power PON distribution network solution
AcWing 1812. Square pasture (enumeration)
58页西门子机床行业数字化解决方案
IT服务管理框架要怎么落地?看这篇就够了
On the import and export of browser bookmarks
Mysql
JUC并发学习笔记
Loading and unloading of embedded driver module
外贸公司一般用什么邮箱,电子邮件如何群发?
EL&JSTL
Introduction to openlayers (I)
Can station B be called YouTube in China?
什么是电子邮件的格式?企业邮箱地址是什么?
Glass: GNN tagging technique for subgraph representation learning