[英]MySQL Grant User Privileges Error
I have a question regarding how to grant privileges MySQL user accounts. 我有一个关于如何授予MySQL用户帐户特权的问题。 I have a MySQL user account, and in my example code I would like to grant privileges to the whole database.
我有一个MySQL用户帐户,在我的示例代码中,我想授予整个数据库特权。 When I run the code, I get the following error:
运行代码时,出现以下错误:
Access denied for user 'user'@'10.%' to database 'testDB' 用户'user'@'10.%'对数据库'testDB'的访问被拒绝
Here is my source code: 这是我的源代码:
<?php
$connection = mysql_connect("sql.example.com", "user", "password");
mysql_select_db("test");
$query = mysql_query("GRANT ALL PRIVILEGES ON test.* To 'user'@'localhost'
IDENTIFIED BY 'password'");
if (!$query) {
die(mysql_error());
}
echo "Success!";
?>
Why am I getting that error? 为什么会出现该错误? Could someone please help my with this?
有人可以帮我吗? I would really appreciate it!
我真的很感激!
Looks like you have no access to your mysql server with that credentials: 似乎您无法使用该凭据访问mysql服务器:
"sql.example.com", "user", "password"
Try first to create a user with the password and after that connect to mysql. 首先尝试用密码创建一个用户,然后再连接到mysql。
Enter to the mysql server with root user that you have, that way: 使用您具有的root用户身份输入到mysql服务器:
shell> mysql --user=root mysql
After that create the user that you going to connect with: 之后,创建您要与其连接的用户:
shell> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
And then give him permissions: 然后给他权限:
shell> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' WITH GRANT OPTION;
Don`t forget to set you host for connection, in the example it is localhost, but in your case it could be something else. 不要忘记为连接设置主机,在该示例中为localhost,但是在您的情况下,它可能是其他主机。
I guess it's the same problem with php like a native query --> you need to execute "flush privileges" after the grant statement - otherwise the user table doesn't get updated. 我想这与php一样,就像本机查询一样->您需要在Grant语句后执行“刷新特权”-否则用户表不会得到更新。
http://dev.mysql.com/doc/refman/5.5/en/adding-users.html http://dev.mysql.com/doc/refman/5.5/zh-CN/adding-users.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.