5

I am new to PHP. I get the following error when executing my application:

In phpMyadmin the code is like this

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;

As I have taken back up, I have change the above code to

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'Pass123';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;

Now I am get the following error

Access denied for user 'root'@'localhost' (using password: YES) MySQL Error # :1045

Please let me know, what went wrong here.

Jocelyn
  • 10,531
  • 10
  • 40
  • 55
Gnanendra
  • 63
  • 1
  • 3
  • 7
  • Have you confirmed whether 1) you have the correct username/password? 2) Whether your domain can actually connect to the mysql server (use phpMyAdmin to verify this) – JohnP Apr 05 '11 at 04:43
  • Have you done a little searching, see http://stackoverflow.com/questions/2912761/beginner-mysql-error-access-denied http://stackoverflow.com/questions/2540794/unable-to-access-mysql-from-myphpadmin-after-setting-root-password-in-easyphpwam http://stackoverflow.com/questions/3532868/mysql-error-1045-access-denied – gideon Apr 05 '11 at 04:45
  • share some code.... so we can help, seems that you are not passing the right pasword to the function mysql_connect – Necronet Apr 05 '11 at 04:46
  • [Search stackoverflow with google](http://www.google.com/search?q=access+is+denied+for+user+'root'%40localhost+mysql+error+1045&sitesearch=stackoverflow.com/questions&qscrl=1) – gideon Apr 05 '11 at 04:46
  • 2
    It was working fine.. If enter wrong password then it was showing Error message as "Incorrect password". but now its directly showing error page.... – Gnanendra Apr 05 '11 at 05:00
  • @JohnP: "access denied" means it can connect, but couldn't log in. If it was a connection issue, it'd be "connection refused" – Marc B Apr 06 '11 at 20:54

7 Answers7

3

After wasting most of a day on this problem, it turned out that all i had to do was supply the non-localhost hostname. I've no idea why (the user is allowed to connect from Any host), but it works!

root@base:~# mysql -u username -h hostname -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

And in PHP:

Test 1807:
<?php
$username = "username";
$password = "password";
$hostname = "actualhostnamenotlocalhost"; 

$con = mysqli_connect($hostname, $username, $password);

// Check connection
if (mysqli_connect_errno($con)){
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_close($con);    

?>
OK.
Cees Timmerman
  • 13,202
  • 8
  • 78
  • 106
2

Nobody here has mentioned that (for some reason or another), the host assigned to your user might be wrong. When it says root@localhost it means the user root with the host of localhost.

On some servers, the default root might not be on localhost. Try these:

root@127.0.0.1

root@[yourhostname]

Alfo
  • 4,413
  • 9
  • 35
  • 50
0

There can be a problem with MySQL-server and the port on which it is run. Default is 3306. If it doesn't work, change the port in the my.ini (ór whatever the mysql-ini filename is) AND also change the port-reference in the config.inc.php in the phpmyadmin-folder.

So, the error that is explained here (by Gnanendra)

Access denied for user 'root'@'localhost' (using password: YES) MySQL Error # :1045

may be given because MySQL-server is not run correctly.

Also check this post for more information on this issue:

Can't start server: Bind on TCP/IP port: No such file or directory

j0k
  • 21,914
  • 28
  • 75
  • 84
pdvries
  • 1,352
  • 2
  • 9
  • 18
0

Make sure the password correct (caps lock?) and perhaps use the raw IP address i.e. 127.0.0.1

Ed Heal
  • 55,822
  • 16
  • 77
  • 115
0

Please check the password which you typed here.

These kind of errors come when youre password is not matching with the original password.

sreekanth
  • 1,091
  • 2
  • 11
  • 21
0

make sure whether you've assigned a password for mysql

Mujahid
  • 1,177
  • 5
  • 29
  • 58
0

For resetting youre password please look into this page http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

sreekanth
  • 1,091
  • 2
  • 11
  • 21