NewUser
NewUser

Reputation: 13323

Mysql database connection error

whenever I am trying to connect phpMyadmin through php script it is showing some errors like this Warning: mysql_connect(): Access denied for user 'www-data'@'localhost' (using password: NO) I am using ubuntu 11.04.So can you tell me how to solve this?

Upvotes: 1

Views: 4707

Answers (2)

IAmTimCorey
IAmTimCorey

Reputation: 16755

This error simply means that your connection information is incorrect. You are trying to connect to the MySQL database using the username "www-data@localhost" with no password. Check your MySQL permissions to see what you need to do. Either this login needs a password or this login is not specified as being permitted to access the data.

To check what permissions you have for that user, run this MySQL script:

SELECT * FROM user WHERE user='www-data';

To add rights to that user (if they are missing), run this script:

GRANT SELECT ON database.* TO 'www-data'@'localhost';

Upvotes: 2

Vinnyq12
Vinnyq12

Reputation: 1559

This works for me.

$dbhost = 'localhost';
$dbuser = 'www-data';
$dbpass = '<PUT PASSWORD FOR  HERE>';
$dbname = '<YOUR DATABASE NAME>';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Could not connect: ' . mysql_error());
mysql_select_db($dbname);

Upvotes: 0

Related Questions