MySQL数据库上的用户访问被拒绝 [英] Access denied for user on MySQL database

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

问题描述

我在我的网站上只有一个用户使用两个数据库。第一个和较旧的数据库DB_A是真实数据库,而较新的DB_B仅用于测试目的。

I have a single user for two databases on my website. First and older database DB_A is real database while newer DB_B is just for testing purposes.

我的用户,我们称它为USER_X都具有所有特权('DROP'除外)

My user, let's call it USER_X has all privileges (except 'DROP') on both of them and I'm sure that my username, password and DB name are all written correctly within PHP.

在连接到DB_A并抛出
<$ c时,我确定它们的用户名,密码和数据库名称都正确地在PHP中写了。 $ c> if(!mysql_select_db($ dbname))echo mysql_error();
我什么也没得到,换句话说,一切正常。

When connecting to DB_A and throwing if(!mysql_select_db($dbname)) echo mysql_error(); I get nothing, in other words, everything works fine.

当连接到DB_B并抛出相同的错误时,我得到
用户'USER_X'@'localhost'对数据库'DB_B'的访问被拒绝

When connectin to DB_B and throwing the same thing, I get Access denied for user 'USER_X'@'localhost' to database 'DB_B'.

再次,我确定我的凭据正确并且对DB_B数据库拥有所有特权。

Once again, I'm sure my credentials are correct and that I have all privileges on the DB_B database.

有人知道这里发生了什么吗?

Anyone has an idea what's going on in here?

谢谢!

编辑:

PHP v.5.2.17

PHP v.5.2.17

MySQL v.5.0.96

MySQL v.5.0.96

推荐答案

使用 MySQLi - http://www.php.net/manual/zh/book.mysqli.php -不推荐使用 MySQL

查看您的实际代码将非常有用!

It would be really useful to see your actual code!

无论如何,以下内容来自 http://www.php.net/manual/en/mysqli.connect-error.php

Anyway, the following are from http://www.php.net/manual/en/mysqli.connect-error.php

如果您仍然可以错误,然后检查用户名,密码和数据库拼写是否正确。

I suggest trying them, if you still get an error, then check username, password and DB spelling are ok.

面向对象样式

$mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db');

// Works as of PHP 5.2.9 and 5.3.0.
if ($mysqli->connect_error) {
     die('Connect Error: ' . $mysqli->connect_error);
}

程序样式

 $link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');

 if (!$link) {
     die('Connect Error: ' . mysqli_connect_error());
 }

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

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