php Mysql 无法连接 - 访问被拒绝(使用密码是)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12633020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:56:18  来源:igfitidea点击:

Mysql cannot connect - Access denied (using password yes)

phpmysqlcpanel

提问by user1443519

I have hosting provided by eleven 2 and I just created a new MySQL user and gave it access to every action listed.

我有 11 2 提供的主机,我刚刚创建了一个新的 MySQL 用户,并授予它访问列出的每个操作的权限。

I'm getting the following error

我收到以下错误

Warning: mysql_connect() [function.mysql-connect]: Access denied for user '(username is here, removed for posting)' (using password: YES) in /home/.../public_html/config.php on line 10

Here is my config file

这是我的配置文件

//connection details have been removed for posting purposes

<?php

 define('SQL_SERVER',''); // Database Server
 define('SQL_USER',''); //  User
 define('SQL_PASS',''); //  Password
 define('SQL_DB',''); //  database



 mysql_connect(SQL_SERVER,SQL_USER,SQL_PASS) or die("Error: ".mysql_error()); // Connection to the server
 mysql_select_db(SQL_DB) or die("Error: ".mysql_error()); // Connecting to the database
?>

I tried to do the following as suggested by this post Access denied for user 'someuser'@'localhost' (using password: YES)

我尝试按照这篇文章的建议执行以下操作Access denied for user 'someuser'@'localhost' (using password: YES)

GRANT ALL PRIVILEGES ON databasename.* TO 'bookorama'@'%' IDENTIFIED BY 'yourpassword';
FLUSH PRIVILEGES;

But I got the following error "#1044 - Access denied for user". When I log into the CPanel and check out the database users, it shows the user that I tried to log in as, so I'm confused as to why it won't work.

但是我收到以下错误“#1044 - 用户拒绝访问”。当我登录到 CPanel 并检查数据库用户时,它显示了我尝试登录的用户,所以我很困惑为什么它不起作用。

EDIT - I got it to work. There was something wrong with the server. Contacted the host and they took care of it. Thanks for the replies.

编辑 - 我让它工作了。服务器有问题。联系了房东,他们处理了。感谢您的回复。

回答by user1104854

I stumbled upon this connection info about Cpanel http://www.inmotionhosting.com/support/community-support/databases/1045-access-denied-for-user-mysql-error

我偶然发现了有关 Cpanel http://www.inmotionhosting.com/support/community-support/databases/1045-access-denied-for-user-mysql-error 的连接信息

Your cPanel username and password can be used to connect to your databases (as well as your cPanel). If you're connecting to your database using your cPanel username and password, you can reset your cPanel password to ensure you are using the correct username and password.

If you setup a MySQL username and password specifically for accessing a database, you'll want to ensure you are using the correct username in your php scripts. For example, MySQL usernames are always in this format:

cpanel-username_mysql-username

If your cPanel username is userna5 and you created a database username of dbuser1, then the actual database username would be:

userna5_dbuser1

您的 cPanel 用户名和密码可用于连接到您的数据库(以及您的 cPanel)。如果您使用 cPanel 用户名和密码连接到数据库,则可以重置 cPanel 密码以确保使用正确的用户名和密码。

如果您专门为访问数据库设置了 MySQL 用户名和密码,您需要确保在 php 脚本中使用正确的用户名。例如,MySQL 用户名始终采用以下格式:

cpanel-用户名_mysql-用户名

如果您的 cPanel 用户名是 userna5 并且您创建的数据库用户名是 dbuser1,那么实际的数据库用户名将是:

userna5_dbuser1

Temporarily, I'd suggest changing your databse password to that of your Cpanel account just to eliminate any doubts.

暂时,我建议将您的数据库密码更改为您的 Cpanel 帐户的密码,以消除任何疑问。

回答by user786

Usually the password field is not required unless you set a password for mysql.

通常不需要密码字段,除非您为 mysql 设置密码。

you can use mysql_connect("hostname","username","")

您可以使用 mysql_connect("hostname","username","")

But if you have set the password for your mysql then you have to write password while connecting. And if still it doesn't working , then might be you have to look at your username and password.

但是如果你已经为你的 mysql 设置了密码,那么你必须在连接时写密码。如果仍然无法正常工作,那么您可能需要查看您的用户名和密码。

回答by Mayo Watro

What is your sql server ? some companies change the server name from local host to something else to security purpose - Well but if its saying access denied for user that is may be your are connecting to wrong database ? that is

你的sql服务器是什么?一些公司出于安全目的将服务器名称从本地主机更改为其他名称 - 好吧,但是如果它说用户拒绝访问可能是您连接到错误的数据库?那是

mysql_select_db(SQL_DB)

Are you sure you are using the correct database name ? and you are able to log into your SQL account with same username and password ? well if the problem still persist trying using the root account of SQL the super admin hope you are on your local computer or have a dedicated server.

您确定您使用的是正确的数据库名称吗?并且您可以使用相同的用户名和密码登录您的 SQL 帐户吗?好吧,如果尝试使用 SQL 的 root 帐户问题仍然存在,超级管理员希望您在本地计算机上或拥有专用服务器。

Why don't you try using them in this form -

你为什么不尝试以这种形式使用它们 -

$con = mysql_connect("host name","username","password");
$db = mysql_select_db("database name",$con);

回答by WajhuAllah Hussain

I had same issue, I was trying to connect between two different Web Servers. If I use my PHP script on same server the connection will establish but if I use the same script file from other Web Server (Web Hosting) it gave this error.

我有同样的问题,我试图在两个不同的 Web 服务器之间进行连接。如果我在同一台服务器上使用我的 PHP 脚本,连接将建立,但如果我使用来自其他 Web 服务器(Web 托管)的相同脚本文件,则会出现此错误。

I solved it by allowing access to MySQL Server (Remote MySQL) by providing the IP address from where I used to connect.

我通过提供我曾经连接的 IP 地址来允许访问 MySQL 服务器(远程 MySQL)解决了这个问题。

it is also worth noting that I used Domain but Domain Name did not work for me. Also both CPanel and itself MySQL users could connect to MySQL Server. Hope its helpful for you also.

还值得注意的是,我使用了域,但域名对我不起作用。此外,CPanel 和 MySQL 用户本身都可以连接到 MySQL 服务器。希望它对你也有帮助。