无法登录到新的 mysql 用户

无法登录到新的 mysql 用户

当我创建一个新的 Mysql 用户时,无法使用该用户和密码登录。只有创建一个没有密码的用户,我才能登录。

例如:

mysql -u root -phererootpass
 grant all privileges on mydb.* to testuser@'%' identified by '' with grant option;
 grant all privileges on mydb.* to testuser2@'%' identified by 'mypass' with grant option;
 FLUSH PRIVILEGES;
 exit;

mysql -u testuser  #<<< work fine

mysql -u testuser2 -pmypass  #<<< fail to login
ERROR 1045 (28000): Access denied for user 'testuser2'@'localhost' (using password: YES)
</code>

我在 Red Hat v5 上使用 Mysql 5.0

请指教莫斯塔尔

答案1

您所设置的仅允许您从所有其他服务器进行连接以外localhost。您也需要运行这个

grant all privileges on mydb.* to testuser2@'localhost' identified by 'mypass' with grant option;

然后记得刷新你的权限。

答案2

尝试设置环境变量MYSQL_PWD?

导出MYSQL_PWD ='
mypass'mysql -u testuser2 -p

根据我的经验,将密码作为 CLI 的一部分传递是一个坏主意。(它会显示在您的进程列表中,任何用户都可以通过“top”查看)

相关内容