mysql“拒绝用户访问" (仅在通过php连接时发生) [英] mysql "access denied for user" (only happens when connecting via php)
问题描述
我创建了用户dashboard
,并为其授予了各种特权(例如SHOW DATABASES
).我最初将Host = [web服务器的专用ip]设置为主机,但是由于php的mysql_connect
返回的访问拒绝错误一直存在,所以我设置了Host=192.168.%
以便网络上的任何计算机都可以访问它.
I created user dashboard
and granted it various privileges (such as SHOW DATABASES
). I initially set the Host=[private ip of web-server], but kept getting access denied errors returned from php's mysql_connect
, so I set Host=192.168.%
so any machine on our network can access it.
我可以使用MySQLWorkbench从Mac成功连接到Db服务器上的mysql Db(并成功运行SHOW DATABASES;
),但是当我尝试通过Web服务器上的php连接时,我得到的是:Access denied for user 'dashboard'@'192.168.xx.xx' (using password: YES)
I can successfully connect to the mysql Db on the Db server from my Mac using MySQLWorkbench (and successfully ran SHOW DATABASES;
), but when I just try to connect via php on our webserver, I just get: Access denied for user 'dashboard'@'192.168.xx.xx' (using password: YES)
我在php中使用的代码是:
the code i'm using in php is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<?php
$dbhost = "192.168.x.x"; // but no x's
$dbuser = "dashboard";
$dbpass = "password"; // i copied&pasted the real password for other successful logins
$dbconnect = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
$query = mysql_query('SHOW DATABASES;');
?>
</head>
<body>
<? echo $query ?>
</body>
</html>
与半相关的注释:我可以以某种方式将$dbpass
设置为等于加密的字符串,以使其不存储纯文本吗?
Semi-related note: Can I somehow set $dbpass
equal to an encrypted string so it's not stored a plain-text?
编辑:mysql用户当前为dashboard@192.168.%
(不是本地主机)
EDIT: the mysql user is currently dashboard@192.168.%
(not localhost)
编辑2 :我认为由于Web服务器位于DMZ中,因此它可能是通过其公用IP与MySQL进行通信的,但是当我将dashboard
的主机更改为该主机时,我获取Host '192.168.xx.xx' is not allowed to connect to this MySQL server
.看来情况并非如此……
EDIT 2: I thought since the Web Server is in the DMZ, that it might be communicating with MySQL from it's public IP, but when I change the host of dashboard
to that, I get Host '192.168.xx.xx' is not allowed to connect to this MySQL server
. So it seems that is not the case…
推荐答案
密码包含一个保留字符,因此在PHP中,密码必须用单引号而不是双引号引起来.
The password contained a reserved character, so in PHP it needed to be enclosed with single quotes instead of double quotes.
这篇关于mysql“拒绝用户访问" (仅在通过php连接时发生)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!