# Mysql: Access denied for user



## colorado97

I'm trying to set up a script but any user with a password that I've set up in MySQL (except for root user) is not able to access the databases. If the user does not have a password, it works. Any suggestions about why I'm getting errors such as the following would be welcome:

Warning: Access denied for user: '[email protected]' (Using password: YES) in sys:/apache/html/poll/db/include/class_mysql.php on line 32

Warning: MySQL Connection Failed: Access denied for user: '[email protected]' (Using password: YES) in sys:/apache/html/poll/db/include/class_mysql.php on line 32
Connection Error

MySQL Error : Connection Error
Error Number: 1045 Access denied for user: '[email protected]' (Using password: YES)
Browser : Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
Referer : http://www.mysite.net/poll/
PHP Version : 4.2.4-dev
Server : Apache/1.3.27 (NETWARE) PHP/4.2.4-dev mod_jk/1.2.2-dev
Script Name : /poll/db/index.php


----------



## Rockn

The code referencing line 32 of the page it is failing on would be helpful.


----------



## colorado97

31 function connect() {
32 $this->conn_id = mysql_connect($this->db['host'].":".$this->port,$this->db['user'],$this->db['pass']);
if ($this->conn_id == 0) { 
$this->sql_error("Connection Error");
}
if (!mysql_select_db($this->db['dbName'], $this->conn_id)) {
$this->sql_error("Database Error");
}
return $this->conn_id;
}

Line 32 is shown above. It just connects with the database using the password and username defined in another included file. Whether it's this program or whether I try to log into MySQLadmin directly, it doesn't work. Only the mysql root user is able to log in.


----------



## CharlieMouse

did you grant access to that user. read this and make sure that user has perrmission

mysql> GRANT ALL ON databaseName.* TO 'your_mysql_name'@'your_client_host';

where your_mysql_name is the MySQL username assigned to you and your_client_host is the host from which you connect to the server

here you go. Just in case 

ftp://mirror.mcs.anl.gov/pub/mysql/Downloads/Manual/manual.pdf


----------



## colorado97

Thanks for the reply. The user did have privileges assigned to the needed database. The problem apparently was that I needed to flush privileges and had to specify the host as localhost rather than using %. 

Without the localhost account, the anonymous-user account for localhost that is created by mysql_install_db took precedence when my user connected from the local host. As a result, the user was treated as an anonymous user. The reason for this was that the anonymous-user account has a more specific Host column value than the 'user'@'%' account and thus came earlier in the user table sort order. (In the manual you link to the user table sorting is discussed in section 5.4.5 Access Control, Stage 1: Connection Verification starting on page 324 (291) of the PDF file.)


----------



## satondnet

We got this error on our computer - 

Warning: mysql_pconnect(): Access denied for user 'root'@'localhost' (using password: YES) in G:\PHP\php2.php on line 4

PHP version - 4.2
MySQL - 5.0.2

The solution to the above problem is as follows - 

1) Check your hostname, username and password from the MySQL monitor, by using the following query - select host,user, password from user;
User is a table in the MySQL database (in case u did'nt know  )

2) Now use the above values while using the mysql_pconnect() function.

3) If the error persists then - go to the MySQL monitor and change the password using the following command - 

mysql> SET PASSWORD FOR
-> [email protected]
-> =OLD_PASSWORD('');
Query OK, 0 rows affected (0.06 sec)

Where root and localhost are the values obtained using the select query as mentioned in point no. 1)

4) Now, use the blank password set above in your mysql_pconnect function, along with the same username and password.:up: 

This worked in our case...but we're still not sure why...
So in case this code is being used at a nuclear power station or something...ALL THE BEST!!


----------

