0

删除表时出错:

SQL query:

DROP user IF EXISTS  's01'@'%';


MySQL said: Documentation

#1064 - 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 'if exists 's01'@'%'' at line 1 

不删除表的错误:

SQL query:

/*Students*/ CREATE User 's01'@'%' IDENTIFIED BY  'pw1';


MySQL said: Documentation

#1396 - Operation CREATE USER failed for 's01'@'%' 

我的一些代码示例:

Drop user if exists 's01'@'%';

flush privileges;

/*Students*/
Create User 's01'@'%' Identified by 'pw1';

我不完全知道出了什么问题。我查了一下,它说添加刷新权限,但我仍然得到相同的两个错误。

4

1 回答 1

1

使用 . 检查您的 mysql 版本select version();。的IF EXISTS选项DROP USER是在 5.7 中添加的。如果您没有使用 5.7,那么这可能解释了您的第一个错误。

通过查询mysql.user表检查用户是否存在。

从 mysql.user 中选择用户、主机,其中 user = 's01';

此外,由于您没有指定主机名,只需执行

如果存在“s01”,则删除用户;
创建由“pw1”标识的用户“s01”;

通配符主机 (@'%') 是隐含的。

还要执行SHOW GRANTS以验证您的用户是否具有创建和删除用户的正确权限。

于 2017-09-06T17:25:59.927 回答