通过PHP访问连接到MySQL数据库被拒绝 [英] connecting to MySQL database through PHP access denied

查看:136
本文介绍了通过PHP访问连接到MySQL数据库被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试连接数据库时出现拒绝访问错误".这是代码:

I'm getting the 'access denied error while trying to connect to the database. Here is the code:

    <?php
    mysql_connect("00.00.00.00:00000","user","pass");
    mysql_select_db("dbname");

    $q=mysql_query("CALL  GetMaterialInfo('".$_REQUEST['user']."','".$_REQUEST['pass']."','6c3e91d3')");
    while($e=mysql_fetch_assoc($q))
        $output[]=$e;

    print(json_encode($output));

    mysql_close();
    ?>

我更改了课程主机的IP地址(并非全为零)以及用户名,密码和数据库名称.我确定用户名和密码(例如主机ip和端口号以及数据库名称)正确无误.我设法通过JDBC连接器连接到所有数据库,但通过PHP脚本给出了以下错误:

I changed the ip adress of the host ofcourse (its not all zero's) and the username and password and database name. I'm sure the user and password, aswel as the host ip and portnumber and the database name are correct. I managed to connect to the database allready with JDBC connector but it gives the following error through PHP script:

<b>Warning</b>:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user 'username'@'192.168.1.1' (using password: YES) in <b>/www/zxq.net/t/e/s/testphpbach/htdocs/Connection.php</b> on line <b>2</b><br />


推荐答案

您需要进行以下检查:

  1. 检查192.168.1.1是否包含在/etc/hosts中.如果您的数据库位于本地主机上,请尝试使用本地主机代替ip.
  2. 检查端口是否打开.尝试使用telnet(例如ip/localhost) .例如telnet本地主机2222
  3. 检查数据库是否具有授予您的用户名和密码的特权.要检查特权,请使用SHOW GRANTS [FOR user].可以在此处找到更多信息. 如果这些都不起作用,请尝试使用默认用户以外的其他用户.
    让我们知道发生了什么
  1. Check that 192.168.1.1 is included in /etc/hosts . If your db is on a localhost machine , try using localhost instead of ip.
  2. Check if the port is open . Try using telnet ( e.g. ip/localhost) . e.g. telnet localhost 2222
  3. Check if the database has the granted privileges for your username and password. For checking privilege , use SHOW GRANTS [FOR user] . More info can be found here If none of this work, perhaps try using a different user other than the default one.
    Let know what happens

这篇关于通过PHP访问连接到MySQL数据库被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆