新手问题 Rails 切换数据库报错

topswim · November 22, 2012 · Last by topswim replied at November 22, 2012 · 4093 hits

已修改 database.yml: ~/mds/config$ cat database.yml

MySQL. Versions 4.1 and 5.0 are recommended.

Install the MYSQL driver

gem install mysql2

#

Ensure the MySQL gem is defined in your Gemfile

gem 'mysql2'

#

And be sure to use new-style password hashing:

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development: adapter: mysql2 encoding: utf8 reconnect: false database: mds_development pool: 5 username: root password: socket: /var/run/mysqld/mysqld.sock

Warning: The database defined as "test" will be erased and

re-generated from your development database when you run "rake".

Do not set this db to the same as development or production.

test: adapter: mysql2 encoding: utf8 reconnect: false database: mds_test pool: 5 username: root password: socket: /var/run/mysqld/mysqld.sock

production: adapter: mysql2 encoding: utf8 reconnect: false database: mds_production pool: 5 username: root password: socket: /var/run/mysqld/mysqld.sock

运行 rake: ~/blog$ rake db:create rake aborted! Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (mysql2 is not part of the bundle. Add it to Gemfile.)

提示要安装 gem install activerecord-mysql2-adapter 安装: ~/blog$ gem install activerecord-mysql2-adapter Building native extensions. This could take a while... ERROR: Error installing activerecord-mysql2-adapter: ERROR: Failed to build gem native extension.

/home/liucc/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb checking for rb_thread_blocking_region()... yes checking for rb_wait_for_single_fd()... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lz... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lsocket... no checking for mysql_query() in -lmysqlclient... no checking for main() in -lnsl... yes checking for mysql_query() in -lmysqlclient... no checking for main() in -lmygcc... no checking for mysql_query() in -lmysqlclient... no *** extconf.rb failed ***

求助为何安装 MYSQL adapter 报错!?!

#1 楼 @woaigithub ~/blog$ sudo gem install activerecord-mysql2-adapter [sudo] password for liucc: Fetching: mysql2-0.3.11.gem (100%) Building native extensions. This could take a while... ERROR: Error installing activerecord-mysql2-adapter: ERROR: Failed to build gem native extension.

/usr/bin/ruby1.9.1 extconf.rb /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- mkmf (LoadError) from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire' from extconf.rb:2:in `'

Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11 for inspection. Results logged to /usr/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

哪位好心人帮我看看啊!为什么 require': cannot load such file -- mkmf (LoadError) 没有这个文件,需要安装什么啊!

虽然 MYSQL 连接器安装了,但是用不了啊! 提示: :~/blog$ rake db:create rake aborted! can't convert Fixnum into String /home/liucc/.rvm/gems/ruby-1.9.2-p320/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in connect' /home/liucc/.rvm/gems/ruby-1.9.2-p320/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:ininitialize'

#1 楼 @woaigithub 不是 sudo 的问题!是要增加 libmysql-ruby libmysqlclient-dev 两个包

You need to Sign in before reply, if you don't have an account, please Sign up first.