用户 'root'@'localhost' 的 MYSQL 访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18328153/
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
MYSQL Access denied for user 'root'@'localhost'
提问by user2698684
I did the following steps to use MySQL in Ubuntu:
我按照以下步骤在 Ubuntu 中使用 MySQL:
sudo aptitude install php5-mysql mysql-server
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
sudo mysql -u root mysql
Change root password:
更改root密码:
mysql> UPDATE mysql.user SET Password=PASSWORD('SecurePassword') WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT
Modify /etc/mysql/my.cnf:
修改/etc/mysql/my.cnf:
[client]
user=root
password=SecurePassword
[mysqld]
...
default-time-zone = '+0:00'
Then:
然后:
sudo service mysql start
mysql -u root
mysql> SHOW GRANTS FOR root@localhost
+--------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+--------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '[here is the Securepassword]' |
+-------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
and I receive an error:
我收到一个错误:
Access denied for user 'root'@'localhost' (using password: YES)
用户 'root'@'localhost' 访问被拒绝(使用密码:YES)
回答by Abhik Dey
It was absolutely correct what you did, but I guess it's not working for one small reason.
你所做的完全正确,但我想这不是出于一个小原因。
You should use identified by password
when you are going to grant privileges like this:
identified by password
当您要授予这样的权限时,您应该使用:
mysql> GRANT ALL PRIVILEGES ONE `*`.`*` TO 'root'@'localhost' IDENTIFIED BY PASSWORD
'*A4B6157319038724E3560894F7F932C8886EBFCF' WITH GRANT OPTION;
回答by Rohit Jindal
If you get an error message like this:
如果您收到这样的错误消息:
Warning: mysql_connect(): Access denied for user: ....
then the problem is that your application can not access the database
. This can have several causes:
那么问题是你的应用程序不能access the database
。这可能有多种原因:
First of all, make sure the database settings in your db-config.php
(connection file for your application) are correct, specifically the name
and password
of your MySQL user, the name of your database
, and the name of your MySQL server.
首先,确保您的db-config.php
(您的应用程序的连接文件)中的数据库设置正确,特别是您的 MySQL 用户的name
和password
,您的名称database
,以及您的 MySQL 服务器的名称。
If you're running your own server, you may need to give your MySQL user proper permissions. Log in to MySQL as the MySQL root user and issue these commands:
如果您运行自己的服务器,则可能需要授予 MySQL 用户适当的权限。以 MySQL root 用户身份登录 MySQL 并发出以下命令:
GRANT ALL PRIVILEGES ON database_name TO user@host IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
回答by nguyen
System like Ubuntu prefers to use auth_socketplugin for root account by default. It will try to authenticate by comparing your username in DB and process which makes mysql request; it is described in here
默认情况下,像 Ubuntu 这样的系统更喜欢为 root 帐户使用auth_socket插件。它将尝试通过比较您在数据库中的用户名和发出 mysql 请求的进程来进行身份验证;它在这里描述
The socket plugin checks whether the socket user name (the operating system user name) matches the MySQL user name specified by the client program to the server, and permits the connection only if the names match.
socket插件检查socket用户名(操作系统用户名)是否与客户端程序向服务器指定的MySQL用户名匹配,只有匹配时才允许连接。
Instead you may want to back with the mysql_native_password, which will require user/password to authenticate.
相反,您可能希望使用mysql_native_password 返回,这将需要用户/密码进行身份验证。
About the method to achieve that, I recommend you checking thisout instead.
关于方法来做到这一点,我建议你检查这出代替。