用户“someuser”@“localhost”的访问被拒绝(使用密码:YES)
我在 mysql 中创建了一个名为“somedatabase”的数据库,
CREATE DATABASE somedatabase;
GRANT ALL ON somedatabase.* TO 'someuser'@'localhost' IDENTIFIED BY 'somepassword';
但是当我尝试使用 php 应用程序访问该数据库时,出现以下错误
“mysql_connect() [function.mysql-connect]:访问 拒绝用户“someuser”@“localhost”(使用密码:YES)”
Mysql查询浏览器确实允许我使用用户名:someuser和密码:somepassword登录到该数据库。那为什么我不能通过应用程序连接到数据库
:
$db_url = 'mysql://someuser:*somepassword*@localhost/somedatabase';
I have created a database by name 'somedatabase' in mysql
CREATE DATABASE somedatabase;
GRANT ALL ON somedatabase.* TO 'someuser'@'localhost' IDENTIFIED BY 'somepassword';
but when i try to access this database using php application i get the following error
"mysql_connect() [function.mysql-connect]: Access
denied for user 'someuser'@'localhost' (using password: YES)"
The Mysql query browser does allow me to login to this database using username : someuser and password : somepassword. Then why is that i am not able to connect to database through application.
php code :
$db_url = 'mysql://someuser:*somepassword*@localhost/somedatabase';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 GRANT 时,请勿在某些用户周围使用单引号 (')。
我还假设您在与 MySQL 相同的机器上运行 Apache/PHP。
Do not use singlequote (') around someuser when using GRANT.
I am also assuming that you're running Apache/PHP on the same box as MySQL.
我有同样的问题。我的问题的解决方案是设置主机,由于某种原因 php 没有在任何主机上为用户连接 (%)
I had same problem. the solution of my problem by was setting the host , for some reason php was not connecting for user at any host (%)
试试这个:
将 somedatabase.* 上的所有权限授予由 'somepassword' 标识的 'someuser'@'%';
http://dev.mysql.com/doc/refman/4.1 /en/adding-users.html
Try this:
GRANT ALL PRIVILEGES ON somedatabase.* TO 'someuser'@'%' IDENTIFIED BY 'somepassword';
http://dev.mysql.com/doc/refman/4.1/en/adding-users.html