简体   繁体   English

PHP:mysql_connect()返回true,但mysql_select_db()返回false _ Ubuntu更新后

[英]PHP: mysql_connect() return true But mysql_select_db() return false _ After Ubuntu Update

After update my Ubuntu to 13.10 in php , mysql can connect by any user but can't select database with correct user and pass. 在将我的Ubuntu更新到php中的13.10之后,mysql可以由任何用户连接,但是不能选择具有正确用户的数据库并通过。 seem the User that sent to mysql is empty Instead root. 似乎发送给mysql的用户是空的,而是root。

$myconn = mysql_connect('localhost' , 'root' , 'pass');
$seldb = mysql_select_db('mydb' , $myconn);
$er = mysql_error();

After run $mycon is: "resource id='2' type='mysql link'" 运行后$ mycon是: "resource id='2' type='mysql link'" 2'type "resource id='2' type='mysql link'"

and mysql_select_db() return false ; 和mysql_select_db()返回false

and

$er is: "Access denied for user ''@'localhost' to database 'mydb'" $ er是: "Access denied for user ''@'localhost' to database 'mydb'"

Please help me. 请帮我。 Sorry for my bad English. 对不起,我的英语不好。

You see MySQL thinks you're '' , not root , which is related to this warning from the manual : 您会看到MySQL认为您是''而不是root ,这与手册中的警告有关

If you permit anonymous users to connect to the MySQL server, you should also grant privileges to all local users as user_name@localhost. 如果允许匿名用户连接到MySQL服务器,则还应该以user_name @ localhost的身份授予所有本地用户特权。 Otherwise, the anonymous user account for localhost in the mysql.user table (created during MySQL installation) is used when named users try to log in to the MySQL server from the local machine. 否则,当命名用户尝试从本地计算机登录MySQL服务器时,将使用mysql.user表(在MySQL安装期间创建)中localhost的匿名用户帐户。 For details, see Section 6.2.4, “Access Cotrol, Stage 1: Connection Verification”. 有关详细信息,请参见第6.2.4节“访问控制,阶段1:连接验证”。

“Access Cotrol, Stage 1: Connection Verification” states: “访问控制,第1阶段:连接验证”指出:

The server uses sorting rules that order rows with the most-specific Host values first 服务器使用排序规则,该规则首先对具有最特定主机值的行进行排序

That means if you have an anonymous ''@localhost user, but a less specific (or just sorted later) root@'%' (or something like it) definition never matches because the 'anonymous' rule matches. 这意味着,如果您有一个匿名''@localhost用户,但是一个不太具体(或稍后排序)的root@'%' (或类似名称)定义将永远不会匹配,因为“匿名”规则匹配。 Look through that last link for a more thorough explanation. 浏览最后一个链接以获得更详尽的解释。

What this means is you either: 这意味着您是:

  • GRANT access to root@localhost explicitly. 授予对root@localhost显式访问权限。
  • DROP USER ''@'localhost'; (the anonymous user) (匿名用户)

I would highly recommend the second one: you should have no need for an anonymous user. 强烈建议第二个:您不需要 匿名用户。

I Solve this problem myself. 我自己解决这个问题。 in php.ini file sql.safe _mode was on. 在php.ini文件中sql.safe _mode已打开。 that cause mysql_connect() Always connect as anonymous Ubuntu User. 导致mysql_connect()始终以匿名Ubuntu用户身份连接。

in php.ini file: sql.safe_mode = Off 在php.ini文件中:sql.safe_mode = Off

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM