无法通过PHP连接到MySQL数据库

时间:2022-09-22 16:04:16

I'm building a website with a login using php and mysql. When I try to connect to the database I keep getting error:

我正在建立一个使用php和mysql登录的网站。当我尝试连接到数据库时,我不断收到错误:

Notice: Could not connect to MySQL: Access denied for user 'User'@'localhost' (using password: YES)

注意:无法连接到MySQL:用户'用户'@'localhost'拒绝访问(使用密码:YES)

I have tried to set a new password or no password but keep getting this error. Does somebody know how to fix this?

我试图设置一个新密码或没有密码,但一直收到此错误。有人知道如何解决这个问题吗?

I noticed this error also occurs when using mysql with java apps

我注意到在使用mysql和java应用程序时也会发生此错误

I'm using phpMyAdmin with wamp

我正在使用phpMyAdmin和wamp

Edit: Here is the code. I replaced Username, Pass and Database by User, Pass and Database

编辑:这是代码。我用户,通行证和数据库替换了用户名,通行证和数据库

DEFINE('DATABASE_USER', 'Username');
DEFINE('DATABASE_PASSWORD', 'Pass');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'Database');
date_default_timezone_set('Europe/Brussels');

DEFINE('EMAIL', 'user@email.com');

DEFINE('WEBSITE_URL', 'localhost/wadistjom');

$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);

if (!$dbc) {
   trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}

2 个解决方案

#1


0  

If you are using PhpMyAdmin then you should be able to see all users under the "Users" tab on the PMA startpage. You can also create a new user there.

如果您使用的是PhpMyAdmin,那么您应该可以在PMA首页的“用户”标签下看到所有用户。您还可以在那里创建新用户。

#2


0  

Have you made sure remote access is on for each user? Sounds like that could be an issue (especially if you're having the same issue with Java applications).

您确定每个用户都启用了远程访问吗?听起来这可能是一个问题(特别是如果你在Java应用程序中遇到同样的问题)。

This could should work:

这应该可行:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Pa55w0rd' WITH GRANT OPTION;

(yanked it from How to grant remote access permissions to mysql server for user?)

(从如何为用户授予mysql服务器的远程访问权限中抽出它?)

#1


0  

If you are using PhpMyAdmin then you should be able to see all users under the "Users" tab on the PMA startpage. You can also create a new user there.

如果您使用的是PhpMyAdmin,那么您应该可以在PMA首页的“用户”标签下看到所有用户。您还可以在那里创建新用户。

#2


0  

Have you made sure remote access is on for each user? Sounds like that could be an issue (especially if you're having the same issue with Java applications).

您确定每个用户都启用了远程访问吗?听起来这可能是一个问题(特别是如果你在Java应用程序中遇到同样的问题)。

This could should work:

这应该可行:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Pa55w0rd' WITH GRANT OPTION;

(yanked it from How to grant remote access permissions to mysql server for user?)

(从如何为用户授予mysql服务器的远程访问权限中抽出它?)