rake db:migrate给出了mysql 2 gem的错误

时间:2016-05-16 09:14:30

标签: mysql ruby-on-rails ruby database

我正在尝试在我的某个rails应用中执行rake db:create。我收到的错误是

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"new-db", "pool"=>5, "username"=>"root", "password"=>"password"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)

这就是我database.yml的样子

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: new-db
  pool: 5
  username: root
  password: password

我尝试在上面的代码中添加host:localhost,它没有用。

此外,当我尝试使用mysql -u root -password登录mysql时,我正在

 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

有人可以帮忙吗。

1 个答案:

答案 0 :(得分:-1)

在除第一行EX之外的每一行之前添加制表符空格。以下

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: new-db
  pool: 5
  username: root
  password: password