2

Over the last day or so I'm not able to connect to a database through PHP. Here's what my code connecting to the database looks like

$con = mysqli_connect("localhost","root","password","database"); And here's the strange error.

PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES) in - on line 2

I'd usually get that error if the credentials are incorrect, but I used a GUI and tested the connection with the exact credentials, where therefore means that, that is not the issue. I just started randomly getting this error and have restarted my computer, reinstalled MySQL, and reconfigure the server I've also tried 127.0.0.1 instead of localhost I'm on localhost so I have full control on pretty much anything and I didn't mess with anything causing this issue. Any ideas?

3 Answers 3

1

For some reason the function is trying to connect using the "user" user instead of "root".

You can debug further by adding the error link:

$con= mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($con));

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

8 Comments

You code have a typo...it should be mysqli_error($con) instead of mysqli_error($link)
I mean PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in - on line 2 PHP Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in - on line 2
sorry quickly copied and pasted. have now edited the post. Did you get a better error?
can you please paste the connection as it is. I assume that you are passing the connection data as variables and that one of them is returning 0/1 (boolean) instead of the value.
Here it is $con= mysqli_connect("localhost","root","alistar123","s") or die("Error " . mysqli_error($con));
|
0

Maybe the problem is in mysql server configuration.

You can try to change password and after flush privileges.

Than restart mysql!

Hope this helps! Bye.

Comments

0

I had the same problem as the title of this question, so incase anyone else googles upon this question and wants to start MySql in 'skip-grant-tables' mode on Windows, here is what I did.

Stop the MySQL service through Administrator tools, Services.

Modify the my.ini configuration file (assuming default paths)

C:\Program Files\MySQL\MySQL Server 5.5\my.ini 

In the SERVER SECTION, under [mysqld], add the following line:

skip-grant-tables 

so that you have

# SERVER SECTION # ---------------------------------------------------------------------- # #The following options will be read by the MySQL Server. Make sure that # you have installed the server correctly (see above) so it reads this # file. # [mysqld] skip-grant-tables 

Start the service again and you should be able to log into your database without a password.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.