dongmeng0317 2014-10-31 08:24
浏览 57

使用PHP删除mysql用户

I'm trying to DROP database and its user using PHP. Though I could able to DROP database but failed to DROP user.

Following command which I have tried,

$cpanel_user = 'abc';
$cpanel_user_password = 'xyz';
$conn = mysql_connect($dbhost = 'localhost', $cpanel_user , $cpanel_user_password );

$sql = 'DROP DATABASE dbname';
$retval = mysql_query( $sql, $conn ); // works perfect

$drop_user = "DROP USER 'username'@'localhost'";
$retval = mysql_query( $drop_user , $conn ); 

Unfortunately it showing "Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation".

The user which is use for connection is cPanel user so must be having full privileges.

I refereed other threads like, MySQL: Check if the user exists and drop it but no luck.

Do I missing anything?

  • 写回答

1条回答 默认 最新

  • dousi6087 2014-10-31 09:14
    关注

    You should grant 'CREATE USER' Privileges to the user you used to connect to the database.

    As your code, you should run this statement by the 'root' user:

    GRANT CREATE USER ON *.* TO abc;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害