gpt4 book ai didi

php - 从 MySQL 中删除用户不起作用

转载 作者:行者123 更新时间:2023-11-29 12:16:10 24 4
gpt4 key购买 nike

我正在尝试从 MySQL 服务器删除用户:

$conn = new PDO("mysql:host=$host;port=$port;dbname=mysql;charset=utf8","$adminname", "$pass",array( PDO::ATTR_PERSISTENT => true));
$sql_deleteuser="DELETE FROM `mysql`.`user` WHERE `user`.`User` = '$username'";
//$sql_deleteuser="SELECT `User` FROM `mysql`.`user`";
$PDOStatement3=$conn->prepare($sql_deleteuser);
//$PDOStatement3->bindParam(':username', $username, PDO::PARAM_STR);
$res_exec=$PDOStatement3->execute();

但它不起作用,并且 errorInfo() 中没有错误,我尝试过

$sql_deleteuser="DROP USER '$username'@'%'";

$sql_deleteuser="IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$username') DROP USER [$username]"; 相同的结果。

连接很好,我使用 SELECT 查询对其进行了测试,并且它有效。

我是不是错过了什么。任何帮助将不胜感激。

最佳答案

您没有删除用户的特权/权利

The DROP USER statement removes one or more MySQL accounts. To use it, you must have the DELETE privilege for the mysql database

也许问题是用户有一个开放的连接因为 mysql 文档说:

Important

DROP USER does not automatically close any open user sessions. Rather, in the event that a user with an open session is dropped, the statement does not take effect until that user's session is closed. Once the session is closed, the user is dropped, and that user's next attempt to log in will fail. This is by design.

如何终止连接请参阅此答案:

how to kill mySQL connections

参见文档:

https://dev.mysql.com/doc/refman/5.0/en/drop-user.html

关于php - 从 MySQL 中删除用户不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29770063/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com