本文介绍了MySQL-用户被拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我创建了一个新用户
So, I create a new user
CREATE USER servname_shb IDENTIFIED BY 'password';
授予他所有特权:
GRANT ALL ON *.* TO servname_shb;
到目前为止没有错误.然后,我尝试连接到数据库:
No errors so far. Then I try to connect to database:
$dbhost = "localhost";
$dbname = "servname_shbusers";
$dbuser = "servname_shb";
$dbpass = "password";
$c = mysql_connect($dbhost,$dbuser,$dbpass) or die("Error:".mysql_error());
mysql_select_db($dbname) or die ("Error connecting to databse:".mysql_error());
并得到一个错误:
Access denied for user 'servname_shb'@'localhost' (using password: YES) in <path>
我尝试了FLUSH PRIVILEGES,删除并重新创建了用户-无效.我在做什么错了?
I tried FLUSH PRIVILEGES, dropping and recreating user - no effect. What am I doing wrong?
推荐答案
错误消息已经为您提供了提示.使用此授予语句:
The error messages gives you a hint already. Use this grant statement:
GRANT ALL ON *.* TO 'servname_shb'@'localhost';
或者更好,正如@grantk在评论中指出的那样,将访问范围调整为仅实际需要的范围.
Or better, as @grantk points out in the comments, refine the access scope to only what is actually needed.
这篇关于MySQL-用户被拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!