Mysql2 :: Error:用户'test'@'localhost'对数据库'depot_test'的访问被拒绝 [英] Mysql2::Error: Access denied for user 'test'@'localhost' to database 'depot_test'

查看:77
本文介绍了Mysql2 :: Error:用户'test'@'localhost'对数据库'depot_test'的访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有些困惑.我已经创建了一个数据库,并且使用depot_production数据库没有任何问题.但是,最近每当进行rake测试时,都会出现诸如

I am a bit stumped here. I have created a database and have had no issues using the depot_production database. However, of late whenever I run rake test, I get a bunch of errors like

# Running tests:

EEEEEEEE

Finished tests in 0.031499s, 253.9763 tests/s, 0.0000 assertions/s.

1) Error:
test_should_create_product(ProductsControllerTest):
Mysql2::Error: Access denied for user 'test'@'localhost' to database 'depot_test'

奇怪的是,我认为我的database.yml文件很好.每次我运行db:migrate时,我都会得到一个空行.我还添加了一个用户测试,但我认为仅将其添加到我的开发数据库中.我有点认为我的测试,生产和数据库不存在...

The odd thing is I think my database.yml file is fine. And everytime I run db:migrate I just get an empty line returned to me. I also added a user test, but I think that only added it to my development database. I sorta think my test and production and databases don't exist...

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_development
pool: 5
username: root
password: admin
socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_test
pool: 5
username: test
password: testy
socket: /tmp/mysql.sock

production:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_production
pool: 5
username: prod
password: mypassword
socket: /tmp/mysql.sock

任何建议将不胜感激,谢谢.

Any advice would be appreciated, thanks.

感谢您在这里陪伴我.我觉得自己很近,但是有些奇怪.这是我所做的.

Thanks for sticking with me here. I feel like I am close but something is odd. Here is what I did.

 mysql> use depot_test;
ERROR 1049 (42000): Unknown database 'depot_test'
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| depot_development  |
| development        |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.01 sec)

mysql> use depot_test
ERROR 1049 (42000): Unknown database 'depot_test'
mysql> use test
Database changed
mysql> GRANT SELECT, INSERT, DELETE ON `test` TO test@'localhost' IDENTIFIED BY 'testy';
ERROR 1146 (42S02): Table 'test.test' doesn't exist
mysql> GRANT SELECT, INSERT, DELETE ON `depot_test` TO test@'localhost' IDENTIFIED BY       'testy';
ERROR 1146 (42S02): Table 'test.depot_test' doesn't exist

推荐答案

因此,请首先以 root 身份登录,或者从终端调用您的root用户.

So first login as root or whatever your root user is called from terminal.

mysql -u root -p

CREATE DATABASE depot_test

CREATE USER 'test'@'localhost' IDENTIFIED BY 'mypass123';

USE depot_test

登录到mysql后,向用户test授予特权(记住要更改密码)

Once you are logged in to mysql, grant privileges to the user test (remember to change password)

GRANT ALL privileges on depot_test.* to test@localhost identified by 'mypass123';

FLUSH PRIVILEGES;

您将需要在数据库中将通行证更改为"mypass123".yml

You will need to change your pass to "mypass123" in your database.yml

这篇关于Mysql2 :: Error:用户'test'@'localhost'对数据库'depot_test'的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆