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 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大