运行“rake db:create RAILS_ENV ='development'时发生错误”

时间:2010-05-19 17:47:48

标签: ruby-on-rails rubygems

当我执行上面的命令时,我在终端中收到此错误,

Deans-MacBook:depot dean$ rake db:create RAILS_ENV='development'
(in /Users/dean/src/RailsBook/depot) Couldn't create database for {"username"=>"root", "adapter"=>"mysql", "database"=>"depot_development", "host"=>"localhost", "password"=>nil}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

在数据库配置文件中,我有以下内容:

development:
    adapter: mysql 
    database: depot_development 
    username: root
    password: 
    host: localhost        

我安装了mysql gem,现在我不确定下一步该怎么做。我在Macbook上运行雪豹。有谁知道为什么会发生这种错误? 在此先感谢您 院长
  编辑
在评论中执行了命令并得到以下内容:

Deans-MacBook:depot dean$ rake -t db:create RAILS_ENV='development'
(in /Users/dean/src/RailsBook/depot)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:create
Couldn't create database for {"username"=>"root", "adapter"=>"mysql", "database"=>"depot_development", "host"=>"localhost", "password"=>nil}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)

编辑2 我已经卸载了mysql gem并重新安装它,我注意到这里发生了一个错误:

Deans-MacBook:~ dean$ sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions.  This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...

No definition for next_result

No definition for field_name

No definition for field_table

No definition for field_def

No definition for field_type

No definition for field_length

No definition for field_max_length

No definition for field_flags

No definition for field_decimals

No definition for time_inspect

No definition for time_to_s

No definition for time_get_year

No definition for time_get_month

No definition for time_get_day

No definition for time_get_hour

No definition for time_get_minute

No definition for time_get_second

No definition for time_get_neg

No definition for time_get_second_part

No definition for time_set_year

No definition for time_set_month

No definition for time_set_day

No definition for time_set_hour

No definition for time_set_minute

No definition for time_set_second

No definition for time_set_neg

No definition for time_set_second_part

No definition for time_equal

No definition for error_errno

No definition for error_sqlstate
Installing RDoc documentation for mysql-2.8.1...

No definition for next_result

No definition for field_name

No definition for field_table

No definition for field_def

No definition for field_type

No definition for field_length

No definition for field_max_length

No definition for field_flags

No definition for field_decimals

No definition for time_inspect

No definition for time_to_s

No definition for time_get_year

No definition for time_get_month

No definition for time_get_day

No definition for time_get_hour

No definition for time_get_minute

No definition for time_get_second

No definition for time_get_neg

No definition for time_get_second_part

No definition for time_set_year

No definition for time_set_month

No definition for time_set_day

No definition for time_set_hour

No definition for time_set_minute

No definition for time_set_second

No definition for time_set_neg

No definition for time_set_second_part

No definition for time_equal

No definition for error_errno

No definition for error_sqlstate

我希望这会有所帮助。

3 个答案:

答案 0 :(得分:1)

解决方案升级到64位版本的mysql。

答案 1 :(得分:0)

狂野猜测 - 您的Mysql实例上没有配置密码?您是否尝试从config / database.yml中删除password行?

答案 2 :(得分:0)

使用以下命令重新安装mysql-server和mysql-client:

sudo apt-get install mysql-server mysql-client

然后这里有一些库需要安装以使MySQL可用于ruby:

sudo apt-get install libmysql-ruby

这一切都解决了我的问题。试试吧 !!! :)