耙子流产了!无法加载此类文件 - mysql / mysql_api

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了耙子流产了!无法加载此类文件 - mysql / mysql_api相关的知识,希望对你有一定的参考价值。

我正在开发Fedora 19。

[root@localhost coffee]# ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
[root@localhost coffee]# rails -v
Rails 3.0.

这是我的Gemfile

source 'http://rubygems.org'

gem 'rails', '3.0.9'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'


gem 'mysql'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19', :require => 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators 
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end

当我做rake db:migrate时,我收到了这个错误

[root@localhost coffee]# rake db:migrate
rake aborted!
cannot load such file -- mysql/mysql_api
/home/charul/coffee/config/application.rb:7:in `<top (required)>'
/home/charul/coffee/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)

mysql安装在我的系统中。

[root@localhost coffee]# service mysqld restart
Redirecting to /bin/systemctl restart  mysqld.service

这是我的database.yml文件。

development:
    adapter:  mysql
    encoding: utf8
    database: ajax
    username: root
    password: root123
    host: 127.0.0.1
    port: 3306

另外,bundle install命令工作得很好。

[root@localhost coffee]# bundle install
Using rake (10.1.1) 
Using abstract (1.0.0) 
Using activesupport (3.0.9) 
Using builder (2.1.2) 
Using i18n (0.5.3) 
Using activemodel (3.0.9) 
Using erubis (2.6.6) 
Using rack (1.2.8) 
Using rack-mount (0.6.14) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.38) 
Using actionpack (3.0.9) 
Using mime-types (1.25.1) 
Using polyglot (0.3.3) 
Using treetop (1.4.15) 
Using mail (2.2.20) 
Using actionmailer (3.0.9) 
Using arel (2.0.10) 
Using activerecord (3.0.9) 
Using activeresource (3.0.9) 
Using json (1.8.1) 
Using mysql (2.9.1) 
Using bundler (1.3.5) 
Using rdoc (3.12.2) 
Using thor (0.14.6) 
Using railties (3.0.9) 
Using rails (3.0.9) 
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

任何人都可以帮助如何解决这个问题。谢谢

答案

你应该使用mysql2而不是mysql gem。做就是了:

gem install mysql2

更改database.yml文件中的数据库适配器

development:
   adapter: mysql

development:
   adapter: mysql2

并更改您的Gemfile:

#gem 'mysql'
gem 'mysql2'
另一答案
 env ARCHFLAGS="-arch x86_64" gem install mysql --version '2.8.1' -- --with-mysql-   config=/usr/local/Cellar/mysql/5.5.15/bin/mysql_config

以上是关于耙子流产了!无法加载此类文件 - mysql / mysql_api的主要内容,如果未能解决你的问题,请参考以下文章

错误“...无法加载此类文件 -- mysql2/2.0/mysql2 (LoadError)”。在带有 Ruby 2.0.0 的 Windows XP 上

Ruby:无法加载此类文件 - LoadError

将帮助文件加载到 FactoryBot 文件中会导致“无法加载此类文件”[重复]

无法加载此类文件 -- openssl (LoadError)

LoadError: 无法加载此类文件 -- 目录/文件名

为啥我无法加载此类文件?