mysql数据库权限被拒绝访问_MySQL数据库上的用户访问被拒绝

bd96500e110b49cbb3cd949968f18be7.png

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.

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.

When connecting to DB_A and throwing

if(!mysql_select_db($dbname)) echo mysql_error();

I get nothing, in other words, everything works fine.

When connectin to DB_B and throwing the same thing, I get

Access denied for user 'USER_X'@'localhost' to database '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?

Thanks!

EDIT:

PHP v.5.2.17

MySQL v.5.0.96

解决方案

It would be really useful to see your actual code!

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

Object oriented style

$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);

}

Procedural style

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

if (!$link) {

die('Connect Error: ' . mysqli_connect_error());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值