【问题标题】:Getting Error - Can't find any matching row in the user table出现错误 - 在用户表中找不到任何匹配的行
【发布时间】:2015-02-11 13:59:01
【问题描述】:

我创建了一个新数据库,创建了一个用户并授予该用户所有访问权限。但是当我尝试为localhost 设置密码时。我收到错误 -

Can't find any matching row in the user table

这是我在 php 代码中所做的 -

mysql_query("CREATE DATABASE ".$ThisDBName."",$con1) or die(mysql_error());

mysql_query("GRANT ALL ON ".$ThisDBName.".* to  ".$ThisDBUserName." identified by '".$ThisDBPassword."'",$con1) or die(mysql_error());

我搜索了这个错误并尝试在SET PASSWORD之前使用FLUSH PRIVILEGES

mysql_query("FLUSH PRIVILEGES",$con1) or die(mysql_error());

mysql_query("SET PASSWORD FOR " . $ThisDBUserName ." @'localhost' = PASSWORD(".$ThisDBPassword.")",$con1) or die(mysql_error());

但我仍然遇到同样的错误,无法使用 mysql_connect() 连接。

我也尝试了this similar question 的答案,但这对我也不起作用。

【问题讨论】:

  • 如果您无法使用mysql_ 连接,您是否尝试过mysqli_?另外,您正在运行什么类型的网络服务器?
  • .""mysql_query("CREATE DATABASE ".$ThisDBName."",$con1) 中有什么意义?
  • 当您刚刚使用grant 设置密码时,为什么要分开set password
  • @Fred-ii-是的,我尝试使用 msqli_ 但遇到了同样的问题 - '拒绝用户访问'。我正在使用 xampp localhost。
  • @MarcinOrlowski 我使用set passwordloaclhost 设置密码。因为当我尝试使用 mysql_connect() 连接到数据库时出现错误 -` 用户 'mydb_11161'@'localhost' 的访问被拒绝。

标签: php mysql


【解决方案1】:

您的GRANT 缺少主机掩码。这应该允许您的用户来自任何主机:

mysql_query("GRANT ALL ON ".$ThisDBName.".* to "
              .$ThisDBUserName."@'%' identified by '"
              .$ThisDBPassword."'",$con1) or die(mysql_error());

查看 GRANT 语法:https://dev.mysql.com/doc/refman/5.6/en/grant.html

【讨论】:

  • 我在上面试过但无法连接到数据库。遇到同样的问题 - Access denied for user 'mydb_11170'@'localhost'
猜你喜欢
  • 2012-10-04
  • 1970-01-01
  • 2019-05-21
  • 2019-05-11
  • 2020-08-14
  • 2016-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多