Mysql2 ::错误:访问被拒绝用户'test'@'localhost'到数据库'depot_test'

Dyn*_*ySS 10 mysql ruby-on-rails

我有点难过.我创建了一个数据库,使用depot_production数据库没有任何问题.但是,每当我进行rake测试时,我都会遇到一堆错误

# 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'
Run Code Online (Sandbox Code Playgroud)

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

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
Run Code Online (Sandbox Code Playgroud)

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

谢谢你在这里坚持我.我觉得我很亲密,但有些奇怪.这就是我做的.

 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
Run Code Online (Sandbox Code Playgroud)

133*_*day 28

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

mysql -u root -p

CREATE DATABASE depot_test

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

USE depot_test
Run Code Online (Sandbox Code Playgroud)

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

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

FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)

您需要将您的传递更改为database.yml中的"mypass123"