用户的PHP MySql(1045)访问被拒绝 [英] PHP MySql (1045) Access Denied For User

查看:394
本文介绍了用户的PHP MySql(1045)访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试搜索该问题的现有答案,但是到目前为止,我发现的答案还没有奏效.

I've tried to search for an existing answer to this problem, but the answers I find have not worked thus far.

我一直在尝试使用PHP连接到MySql数据库.我的虚拟主机在Linux上使用cPanel.我用于执行此操作的代码似乎已经足够标准了:

I've been attempting to use PHP to connect to a MySql database. My web host uses cPanel on Linux. The code I'm using to do this seems standard enough:

$mysqli = new mysqli("localhost", "cPanelUsername_dbUsername", "dbPassword", "cPanelUsername_dbName");

我遇到了以下错误:

Failed to connect to MySQL: (1045) Access denied for user 'cPanelUsername_dbUsername'@'localhost' (using password: YES)Access denied for user 'cPanelUsername'@'localhost' (using password: NO) 

  • "localhost" 是MySql服务器所在的主机服务器(看起来像这样)
  • "cPanelUsername" 是我的cpanel用户名
  • "dbUsername" 是数据库用户,我在授予所有权限的情况下将其添加到数据库中
  • "dbPassword" 是dbUsername的数据库密码
  • "dbName" 是数据库名称
    • "localhost" is the host server where the MySql server is located (it seems like this works)
    • "cPanelUsername" is my cpanel username
    • "dbUsername" is the database user, which I added to the database with all permissions granted
    • "dbPassword" is the database password for dbUsername
    • "dbName" is the database name
    • 在其他地方搜索该问题的答案后,我最终在dbName和dbUsername之前添加了cPanel用户名.

      I ended up adding my cPanel username before the dbName and dbUsername after searching for answers to this issue elsewhere.

      看起来我已经正确设置了所有内容,但未建立连接(出现上述错误).我对服务器没有任何直接的控制权,而我不必询问我的Web主机,这可能需要几天的时间才能解决.连接代码有问题吗?

      It looks like I have everything set up correctly but it's not connecting (with the error above). I don't have any direct control over the server that I wouldn't have to ask my web host about, which may take a few days to get sorted out. Do I have something wrong with my connection code?

      推荐答案

      首先检查您授予数据库正确用户访问权限的数据库,该访问权限是从cpanel中的从Mysql数据库中向数据库添加用户"部分提供的.

      First check the database that you gave the proper user access to your database, which is given from Add User to databases from Mysql database section in cpanel.

      在再次检查之后,

      首先尝试使用php中的常规连接代码,

      first try normal connection code in php,

      $con = mysql_connect("localhost","cpanel_username","cpanel_password");
      if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
      

      这篇关于用户的PHP MySql(1045)访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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