如何允许用户登录到 MySQL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2412607/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:28:45  来源:igfitidea点击:

How to allow user to login to MySQL?

mysqlmysql-error-1045

提问by John

As a root mysql user, I executed the following:

作为 root mysql 用户,我执行了以下操作:

grant all on mydb.* to john identified by 'john1';

Then from shell, I tried to login via

然后从shell,我尝试通过登录

mysql -h localhost -u john -pjohn1;

But when I do this, I get the error

但是当我这样做时,我得到了错误

ERROR 1045 (28000): Access denied for user 'john'@'localhost' (using password: YES)

How do I allow john to login to the mysql terminal? Do I need to use the root mysql user to change something in the mysql.user table?

如何让 john 登录到 mysql 终端?我是否需要使用 root mysql 用户来更改 mysql.user 表中的某些内容?

Thanks

谢谢

回答by adamJLev

Try

尝试

GRANT ALL PRIVILEGES on mydb.* to 'john'@'localhost' identified by 'john1';

Or maybe the problem is because you're not specifying the schema. Add "mydb" to the end of your login console command:

或者问题可能是因为您没有指定架构。将“mydb”添加到登录控制台命令的末尾:

mysql -h localhost -u john -pjohn1 mydb

Docs: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

文档:http: //dev.mysql.com/doc/refman/5.1/en/adding-users.html

回答by Joshua Partogi

Try: mysql -h localhost -u john -p

尝试: mysql -h localhost -u john -p

You'll be prompted for as password. Enter your password there instead. If you still can not login, give privelege johnto access localhost

系统将提示您输入密码。在那里输入您的密码。如果您仍然无法登录,请授予john访问权限localhost

GRANT ALL PRIVILEGES on mydb.* to 'john'@'localhost' identified by 'john1';

GRANT ALL PRIVILEGES on mydb.* to 'john'@'localhost' identified by 'john1';

And try login again.

并再次尝试登录。