1

我是rails的新手,我必须为学校制作一个小rails项目,但不知何故我什至无法让我的服务器运行,非常有希望的开始,希望有人能帮助我;-)。

当我尝试启动我的 rails 服务器时,它给了我一个加载错误:

/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
    from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2.rb:8
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler.rb:120:in `require'
    from /Users/sanderdeclerck1/Sites/simple_cms/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:28:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:28
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:27:in `tap'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.8/lib/rails/commands.rb:27
    from script/rails:6:in `require'
    from script/rails:6

我正在运行 rails 3.0.8 和 ruby​​ 1.8.7

有人有什么建议吗?

编辑:忘了提到我在 OS X 10.6.7

4

5 回答 5

1

尝试添加export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH到您的~/.profile. 如果您的 mysql 安装不在,/usr/local您将不得不更改该路径。

于 2011-06-15T17:47:13.453 回答
1

我猜你在 OS X 上,所以你应该在实际加载 mysql Gem 之前先安装 MySQL 。

两种选择:

  1. 请按照此处的指南稍旧的指南了解如何设置所有内容(MySQL、Ruby 和 Rails)。如果你从官方网站安装 MySQL 实际上应该就足够了,但根据我的经验,它涉及到一些摆弄。

  2. 您还可以通过Homebrew安装 MySQL 。这是一个指南。请注意,您必须手动启动它

    launchctl load ~/Library/LaunchAgents/com.mysql.mysqld.plist
    
于 2011-06-15T08:44:19.020 回答
0

如果您使用 Ubuntu,请尝试安装apt-get install ruby-dev libmysql-ruby libmysqlclient-dev软件包

于 2011-06-15T08:44:49.607 回答
0

您可能只需要重新安装 mysql2 gem。

首先你应该找到你的mysql_config。您可以通过发出以下命令来做到这一点:

sudo find /usr/local -name mysql_config

然后安装gem

(sudo) gem install mysql2 -- --with-mysql-config=RESULT_FROM_ABOVE

这应该给你一个配置了你的mysql安装的gem。希望有帮助。

于 2011-06-15T12:34:52.000 回答
0

你是如何安装 MySQL 的?您可能需要在安装 MySQL gem 时指定--with-lib或。--with-mysql-dir

gem install mysql2 -- '--with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include'
于 2011-06-15T09:47:26.100 回答