如何使用db:setup mysql2数据库?

时间:2018-12-14 19:03:36

标签: mysql ruby-on-rails database ruby-on-rails-5 mysql2

我正在轨道5上使用mysql2 gem。如果有帮助,我也使用AWS Cloud9 EC2实例进行开发。

这是我得到的错误:

$ RAILS_ENV=development bundle exec rake db:setup 

rake aborted! 
Mysql2::Error::ConnectionError: 
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

这是我的database.yml文件:

development:
  adapter: mysql2
  socket: /var/mysql/mysql.sock
  database: wagn_development
  username: user
  password: user
  host: localhost

test:
  adapter: mysql2
  socket: /var/mysql/mysql.sock
  database: wagn_test
  username: user
  password: user
  host: localhost

production:
  adapter: mysql2
  socket: /var/mysql/mysql.sock
  database: wagn_production
  username: user
  password: user
  host: localhost

如何解决错误?

1 个答案:

答案 0 :(得分:0)

我相信这与Rails无关。

您正在使用RDS还是数据库在同一台计算机上?

您阅读过此书还是尝试了其中任何一个?我相信这已经释放

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)