简体   繁体   English

Rails3 - Mysql2 - Rake 错误

[英]Rails3 - Mysql2 - Rake error

I am using Rails 3.2 to build rails app with mysql as my development database.我正在使用 Rails 3.2 以 mysql 作为我的开发数据库构建 rails 应用程序。 But when I execute rake db:migrate, the following error occurred.但是当我执行 rake db:migrate 时,出现了以下错误。 For error Fixnum to string, much people say it's because the password is numeric, but my password is already string.对于错误Fixnum to string,很多人说是因为密码是数字,而我的密码已经是字符串了。 I don't know what step that produce the error.我不知道哪个步骤会产生错误。

Please help.请帮忙。

Here is my database.yml这是我的database.yml

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: nwapp_development
pool: 5
username: root
password: mysqlroot
host: 3306

Here is my rake db:create --trace error这是我的 rake db:create --trace 错误

$ rake db:create --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:create
rake aborted!
can't convert Fixnum into String
c:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `initialize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:106:in `rescue in create_database'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:74:in `create_database'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:62:in `block (3 levels) in <top (required)>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:62:in `each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/databases.rake:62:in `block (2 levels) in <top (required)>'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:227:in `call'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:227:in `block in execute'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:222:in `each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:222:in `execute'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:152:in `invoke'

c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:141:in `invoke_task'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `block (2 levels) in top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `each'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `block in top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:108:in `run_with_threads'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:93:in `top_level'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:71:in `block in run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-10.0.2/bin/rake:37:in `<top (required)>'
c:/Ruby193/bin/rake:23:in `load'
c:/Ruby193/bin/rake:23:in `<main>'
Tasks: TOP => db:create

Update 1:更新 1:

Here is updated database.yml这是更新的database.yml

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: nwapp_development
pool: 5
username: root
password: mysqlroot
host: localhost
port: 3306

Here is result from add port and change host这是添加端口和更改主机的结果

$ rake db:create
Can't connect to MySQL server on 'localhost' (10061)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"nwapp_development", "pool"=>5, "username"=>"root", "password"=>"mysqlroot", "host"=>"localhost", "port"=>3306}, charset: utf8, collation:
(if you set the charset manually, make sure you have a matching collation) 
Can't connect to MySQL server on 'localhost' (10061)
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "reconnect"=>false, "database"=>"nwapp_test", "pool"=>5, "username"=>"root", "password"=>nil, "host"=>"localhost"}, charset: utf8, collation:
(if you set the charset manually, make sure you have a matching collation)

Update 2:更新 2:

I need to create manually the database in mysql server.我需要在 mysql 服务器中手动创建数据库。

Here is my database.yml这是我的database.yml

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: nwapp_development
pool: 5
username: root
password: mysqlroot
host: 127.0.0.1
port: 3306

Expanding on mu's comment you need to change host: 3306 to something like host: localhost or host: 127.0.0.1 .扩展 mu 的评论,您需要将host: 3306更改为host: localhosthost: 127.0.0.1

3306 is the default port for mySQL communication so it does not need to be set explicitly. 3306 是 mySQL 通信的默认端口,因此不需要显式设置。 Still if you want to you can have port: 3306 in the database.yml如果你愿意,你可以在 database.yml 中使用port: 3306

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM