mysql_connect()访问被拒绝

时间:2014-01-12 07:50:48

标签: php mysql connection

我遇到了这个连接的问题。我也为这个用户做了“全部授权”

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'kristian'@'localhost' (using password: YES) in connection.php on line 8
Failed to connect to MySQL: Access denied for user 'kristian'@'localhost' (using password: YES)

connection.php

<?php

define('DB_HOST', 'localhost');
define('DB_NAME', 'email');
define('DB_USER', 'kristian');
define('DB_PASSWORD', 'password');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());

?>

1 个答案:

答案 0 :(得分:1)

首先,使用mysqli而不是mysql。也可以尝试运行

GRANT ALL PRIVILEGES ON email.* TO kristian@localhost IDENTIFIED BY 'password';

确保您拥有正确的访问权限。