grant select,update on . to 'usertest'@'localhost' identified by 'testpwd';这行代码为什么报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 'testpwd'' at line 2错误
时间: 2023-08-15 16:08:38 浏览: 45
您缺少指定要授予权限的表或数据库。语法应该是:
```
grant <permission> on <database or table>.<table or column> to '<user>'@'<host>' identified by '<password>';
```
例如,如果要授予 `usertest` 用户对 `mydatabase` 数据库中所有表的 `SELECT` 和 `UPDATE` 权限,并且使用密码为 `testpwd`,则可以使用以下语法:
```
grant select, update on mydatabase.* to 'usertest'@'localhost' identified by 'testpwd';
```
请注意,您可能需要具有足够的权限才能执行此操作。
相关问题
grant select,update on *.* to 'usertest'@'localhost' -> identified by 'testpwd'; 这段代码为什么报错
这段代码可能报错的原因有以下几种可能:
1. MySQL 版本问题:在某些 MySQL 版本中,可能不支持在 `GRANT` 语句中使用 `*.*` 为数据库和表名的通配符,需要明确指定要授权的数据库和表名。
2. 没有足够的权限:执行 `GRANT` 语句需要具有足够的权限,通常需要具有 `GRANT OPTION` 权限或 `SUPER` 权限。如果当前用户没有这些权限,那么该语句将会报错。
3. 语法错误:执行 `GRANT` 语句时,如果语法错误,也会导致该语句报错。你可以仔细检查语法是否正确,比如检查是否有拼写错误、缺少分号等。
你可以根据报错信息进一步排查问题,并进行调整。
grant select,update on *.* to 'usertest'@'localhost' identified by 'testpwd'; 哪里有语法错误
这个 SQL 语句的语法是正确的,但是可能会出现以下两种情况:
1. 如果没有为 'usertest' 用户授权的话,执行该语句会提示错误:`ERROR 1044 (42000): Access denied for user 'youruser'@'localhost' to database '*'`。
2. 如果已经存在 'usertest' 用户,执行该语句会提示错误:`ERROR 1396 (HY000): Operation CREATE USER failed for 'usertest'@'localhost'`,因为该用户已经存在了。
所以,需要确保在执行该语句之前,'usertest' 用户不存在,并且当前用户有足够的权限来授权给 'usertest' 用户。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)