简体   繁体   English

无法在mysql中使用数据库(访问被拒绝)

[英]Unable to use database in mysql (access denied)

I am trying to get started with the following github package: py-gameday . 我正在尝试使用以下github软件包: py-gameday

I installed mysql with brew mysql and created a root password: 我用brew mysql安装mysql并创建了root密码:

> mysqladmin -u root password 'xxx'

I then created a user: 然后,我创建了一个用户:

> mysql -uroot -p 
Enter password: xxx
CREATE USER 'josh'@'localhost' IDENTIFIED BY 'yyy';

Just in case, I reset the password again: 以防万一,我再次重置密码:

SET PASSWORD FOR 'josh'@'localhost' = PASSWORD('yyy');

and I then updated mydb.ini with: 然后我用以下命令更新了mydb.ini

[db]
user=josh
password=yyy
db=gameday

I finally tried running the following: 我终于尝试运行以下命令:

$ mysql -D gameday < gameday.sql -p
Enter password: 
ERROR 1044 (42000): Access denied for user 'josh'@'localhost' to database 'gameday'

In this last step, I tried entering 'xxx' and 'yyy', but none of them worked. 在最后一步中,我尝试输入“ xxx”和“ yyy”,但没有一个起作用。 Why? 为什么?

You need to GRANT access for the user 'josh' to the database 'test'. 您需要授予用户“ josh”对数据库“ test”的访问权限。

GRANT ALL ON test.* TO 'josh'@'localhost';

As long as you don't have NO_AUTO_CREATE_USER set, you can skip the CREATE USER... the following will create the USER and GRANT access in one hit... 只要您没有设置NO_AUTO_CREATE_USER,就可以跳过CREATE USER ...下面将在一次点击中创建USER和GRANT访问权限...

GRANT ALL ON test.* TO 'josh'@'localhost' IDENTIFIED BY 'yyy';

您还必须为该用户设置权限

GRANT ALL ON test.* TO 'josh'@'localhost';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM