php SQLSTATE[28000][1045] 用户 'root'@'localhost' 的访问被拒绝(使用密码:NO)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5397523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLSTATE[28000][1045] Access denied for user 'root'@'localhost'(using password:NO)
提问by Malloc
When I try to connect to my backoffice in my website I get this error :
当我尝试在我的网站中连接到我的后台时,出现此错误:
SQLSTATE[28000][1045]Access denied for user 'root'@'localhost'(using password:NO))
Can someone help me fix this?
有人可以帮我解决这个问题吗?
回答by webdroids
You must use a password. Try to set one with "mysqladmin -u root password NEWPASSWORD"
您必须使用密码。尝试使用“mysqladmin -u root password NEWPASSWORD”设置一个
回答by Ryre
You need to supply a password when logging into your database. When you connect to sql from php, make sure you're supplying this password.
登录数据库时需要提供密码。当您从 php 连接到 sql 时,请确保您提供此密码。
回答by BessKaren
If you set a root password previously, but have forgotten it, you can set a new password. I am working on a Windows machine, and was able to reset the password on the root of MySql using the directions http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html. I created a text file (mysql-init.txt) as follows:
如果您之前设置了 root 密码,但忘记了,您可以设置一个新密码。我在 Windows 机器上工作,并且能够使用http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html 的说明在 MySql 的根目录上重置密码。我创建了一个文本文件(mysql-init.txt),如下所示:
UPDATE mysql.user SET Password=PASSWORD('[choose your password')
WHERE User='root';
FLUSH PRIVILEGES;
At the command line, I entered the following (either make sure you are in the mysql\bin directory or that your path environment variable includes a path to that directory), which will start the server:
在命令行中,我输入了以下内容(确保您位于 mysql\bin 目录中,或者您的路径环境变量包含该目录的路径),这将启动服务器:
mysqld --init-file=C:\mysql-init.txt --console
This printed out a bunch of status statements. To stop the server, I typed this in another command line:
这打印出一堆状态语句。为了停止服务器,我在另一个命令行中输入:
mysqladmin –u root –p[choose your password] shutdown
Of course, replace the [choose your password] with the same password you used in the mysql-init.txt file. In the first command line, you should get more status statements that indicate that the server is shutting down.
当然,用你在 mysql-init.txt 文件中使用的相同密码替换 [选择你的密码]。在第一个命令行中,您应该获得更多指示服务器正在关闭的状态语句。
Now that you have a password for your root user, you can go back to the connection statement you are using to connect to the database and add the password and user.
现在您有了 root 用户的密码,您可以返回用于连接到数据库的连接语句并添加密码和用户。