-2

I am getting this error everytime im trying to connect to my database

    Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): 
Access denied for user 'root'@'name of the computer' (using password: YES) in PATH_TO_FILE on line 8

I checked the privilege and that's what I got

GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION

with that command

show GRANTS for "root"@"127.0.0.1" 

Furthermore this is how i connect

$mysqli = mysqli_connect('path to server', 'root', 'gourami',"recherche");

but as you can see the name of the user is not the same in the error message...

I have no idea what is going on, because that should normally work..

I wonder if its my host that is blocked but I had that problem before,but the message wasn't the same. I fixed it with the command.

flush hosts;

But this time it didn't work

The database is in another server, before everything was working but now for some reason I cant connect.

0

3 Answers 3

1

If your "Access denied" message states 'root'@'name of the computer'... then you probably need to grant access to 'root'@'IP address of the computer'.

7
  • I give it a try, it didn't give me any error..but it still didn't work
    – Komlan
    Apr 17, 2013 at 15:01
  • Assuming you are providing the right password. What's the IP address that 'name of the computer' resolves to? Maybe your box is setup such that you are connecting to mysql from the IP address of the box instead of localhost, try that.
    – ETL
    Apr 17, 2013 at 15:09
  • I am connecting from the IP address since it's mysql another server.
    – Komlan
    Apr 17, 2013 at 15:30
  • did you grant 'root'@'ip address of your computer' ?
    – ETL
    Apr 17, 2013 at 15:45
  • It creates an error Error code: 1133. Can't find match any matching row in the table
    – Komlan
    Apr 17, 2013 at 15:54
0

I would suggest adding a user who is not root to your database. Connecting your PHP script to the database using root is probably not a great idea.

grant some permissions on webDB.* to webUser identified by 'really_good_password'

to see what permissions your webUser will need, check the MySQL docs http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-database-privileges

That way you limit the damage someone can do if they get hold of the account details for your webUser

8
  • So true... if indeed the OP is trying to connect for non-administrator reasons then that's a very very necessary step.
    – ETL
    Apr 17, 2013 at 15:10
  • I tried that, and for some reason now it's says (using password: NO) instead of (using password: YES) although I put the password..but it still doesn't work
    – Komlan
    Apr 17, 2013 at 15:19
  • Can you post up your connection string or the command you are entering? From the command line mysql -u webUser -p should then prompt you for the password you entered when you added them
    – Steve N
    Apr 17, 2013 at 15:28
  • Yes its already on top
    – Komlan
    Apr 17, 2013 at 15:36
  • Can you connect from the command line as webUser when you are on the server? Did you flush privileges after adding the user?
    – Steve N
    Apr 17, 2013 at 15:40
0
SELECT `Host`, `User` FROM `mysql`.`user`;

This will display the current hosts which each MySQL user can login from. If you need access from any host, it should be updated to %, though strictly not recommended for production servers. In order to access from a server whose IP address is known to you, its IP address should be there in the Host column.

enter image description here

1
  • Thanks but I already went there... I also created another user but even with all this it still doesn't work..
    – Komlan
    Apr 17, 2013 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.