我正在尝试运行rake命令来为我的项目构建数据库。但我正在惹恼以下错误。
Harshas-MacBook-Pro:noise harshamv$ rake db:create
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"noise_development", "pool"=>5, "username"=>"hmv", "password"=>2206, "socket"=>"/var/run/mysqld/mysqld.sock"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"noise_test", "pool"=>5, "username"=>"root", "password"=>"root", "socket"=>"/var/run/mysqld/mysqld.sock"}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}
(If you set the charset manually, make sure you have a matching collation)
Rake db:migrate
Harshas-MacBook-Pro:noise harshamv$ rake db:migrate
rake aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `connect'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `initialize'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:863:in `initialize'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `new'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/Users/harshamv/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/Users/harshamv/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/Users/harshamv/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
但是我可以从CLI连接到mysql。
这是我的Rails配置文件
development:
adapter: mysql2
encoding: utf8
database: noise_development
pool: 5
username: hmv
password: *******
socket: /var/run/mysqld/mysqld.sock