Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql2::错误:拒绝用户访问';测试'@';本地主机';到数据库';车辆段测试和x27;_Mysql_Ruby On Rails - Fatal编程技术网

Mysql2::错误:拒绝用户访问';测试'@';本地主机';到数据库';车辆段测试和x27;

Mysql2::错误:拒绝用户访问';测试'@';本地主机';到数据库';车辆段测试和x27;,mysql,ruby-on-rails,Mysql,Ruby On Rails,我在这里有点不知所措。我已经创建了一个数据库,使用depot_生产数据库没有问题。然而,最近每当我运行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: Acce

我在这里有点不知所措。我已经创建了一个数据库,使用depot_生产数据库没有问题。然而,最近每当我运行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'
奇怪的是,我认为我的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
如有任何建议,将不胜感激,谢谢

谢谢你和我在一起。我觉得我很接近,但有些奇怪。这就是我所做的

 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用户

mysql -u root -p

CREATE DATABASE depot_test

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

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


您需要将数据库中的密码更改为“mypass123”。yml

您需要授予用户“测试”更改“depot_测试”的权限,谢谢!我试了一下,得到了以下结果。错误1046(3D000):未选择数据库。是。您必须选择
depot\u测试数据库,请参阅编辑。抱歉,消息太长。我已经编辑了我原来的帖子并添加了它。谢谢似乎您没有名为
depot\u test
的数据库,但您有一个名为
test
的数据库,因此我们将创建
depot\u test
好听!Rails的安装总是一件痛苦的事情,幸运的是,您只有mysql问题:)
GRANT ALL privileges on depot_test.* to test@localhost identified by 'mypass123';

FLUSH PRIVILEGES;