1

This is my code, on a remote server:

$username = 'myuser';
$password = 'password';
mysql_connect('localhost', $username, $password) or die ('blah blah blah');

And occasionally, it gives me this error:

Access denied for user 'myuser'@'localhost' (using password: NO)

This error persists for around 6 minutes, then fades away

Why does this happen? How can I fix it?

P.S.: Please don't worry about me using mysql_*. I also use mysqli, and the problem also occurs. Please help.

Lucas
  • 16,930
  • 31
  • 110
  • 182
  • What do you mean by "occasionally" and "fades away"? – helion3 Apr 03 '13 at 22:59
  • @BotskoNet Well, like, the problem comes around once every day, stays for six minutes, then goes away. – Lucas Apr 03 '13 at 23:01
  • @BotskoNet Though very occasionally it persists for around 40 minutes. – Lucas Apr 03 '13 at 23:01
  • That's bizarre. Is the MySQL server even responsive during that "downtime"? I've never seen it reject connections inconsistently. Is there only a single MySQL install, locally, and there's no chance the PHP script could begin using different credentials? No one is loading another script/setting different credentials? – helion3 Apr 03 '13 at 23:04
  • I'd suggest to implement a simple log to find out what is being called and making sure your password variable is being filled. also did you have a look into the mysql/php log? perhaps there is a problem in the configuration? – Dominik Apr 03 '13 at 23:04
  • @BotskoNet No, don't think so. Couldn't even access PhpMyAdmin through the cPanel on my website during that time. – Lucas Apr 03 '13 at 23:05
  • That seems like a strong indication of the problem. If you can't even access PMA/Cpanel, there's an issue with the server not responding at all. – helion3 Apr 03 '13 at 23:07
  • Could it be your web host - some sort of DDOS protection. Have you fiddled with any settings like that recently? – acutesoftware Apr 03 '13 at 23:09
  • @BotskoNet No, I can access cPanel & anything not including the mysql connection file, but once it's database related, it stuffs up. – Lucas Apr 03 '13 at 23:09
  • @BotskoNet Yep, and now, it's working again. Voila. – Lucas Apr 03 '13 at 23:11
  • Understood, but I think the fact that when this happens, nothing else seems capable of connecting to the db is an indication that the database server is somehow unavailable. Maybe it's crashing, maybe it's consuming resources due to a bad query, maybe it's being attacked, there are a billion causes. Check your error logs etc to find out where MySQL is going... – helion3 Apr 03 '13 at 23:12
  • @BotskoNet Is it possible to access the logs via cPanel, or the backend files? – Lucas Apr 03 '13 at 23:14
  • @think123 Maybe you should report this to your hosting company ... – HamZa Apr 03 '13 at 23:15
  • @HamZaDzCyberDeV I have, they just haven't helped me solve the problem yet. – Lucas Apr 03 '13 at 23:16
  • I'm not experienced much with cpanel... haven't used it in half a decade. I doubt you can, and agree that this is an issue for your hosting provider to resolve. – helion3 Apr 03 '13 at 23:17
  • What version of MySQL server? – sectus Apr 03 '13 at 23:24
  • @sectus Server version: 5.5.30-log – Lucas Apr 03 '13 at 23:26

1 Answers1

2

Since, the error you are receiving is

Access denied for user 'myuser'@'localhost' (using password: NO)

and not

blah blah blah

as defined in the die ('blah blah blah'); segment; the error is not because of your connection to MySQL server.

This is most probably because the user myuser does not have PRIVILEGES to perform the task you are asking it to do(may be DELETE, may be UPDATE or may even be SELECT)

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • So if the user lacks privileges, the function tell you you aren't using a password even though you are? That does not seem logical! – Ryan Mortensen Oct 04 '13 at 20:24