2

I am using nginx, PHP and MYSQL. I setup a database and a user and I can select it via the MySQL CLI client:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 52
Server version: 5.1.61-0+squeeze1 (Debian)
mysql> use cinema
Database changed

However, it seems not to work when I try to connect to it from my php script:

<?php
$link = mysql_connect('localhost', 'root', '************');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

The output is:

Could not connect: Access denied for user 'root'@'localhost' `(using password: NO)`

(**** is of course my real password...).

Does anyone have an idea why it says (using password: NO) although I clearly use one in my code?

5
  • what about your os and mysql installation? Commented Apr 28, 2012 at 21:50
  • 1
    Sidenote: mysql is not recommended anymore. Use MySQLi, or PDO_MySQL instead. Commented Apr 28, 2012 at 21:50
  • See my post: Server version: 5.1.61-0+squeeze1 (Debian) - let me know if u need to know more details! Commented Apr 28, 2012 at 21:51
  • you can access phpmyadmin by this user and password? you run mysql_secure_install? Commented Apr 28, 2012 at 21:52
  • ilanco solved it! Thanks anyways :) Commented Apr 28, 2012 at 21:58

1 Answer 1

4

It could be that mysql safe mode is on, and then the password field is ignored.

Sign up to request clarification or add additional context in comments.

1 Comment

Simply great! I wonder why it was On in the first place, but nevermind!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.