Bizarre error when trying to connect to database

我是研究僧i 提交于 2019-12-11 03:39:53

问题


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?


回答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));




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/23279934/bizarre-error-when-trying-to-connect-to-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!