【问题标题】:rails-mysql rake db :create - Library not loaded libmysqlclient.20.dylib image not foundrails-mysql rake db :create - 未加载库 libmysqlclient.20.dylib 未找到图像
【发布时间】:2016-02-22 03:05:10
【问题描述】:

原因:找不到图像 - /Users/mdurrant/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.20/mysql2/mysql2.bundle

我们的应用程序需要 mysql 版本 5.6,这似乎可以正常工作 -

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 

但是,当我尝试从 rails 创建数据库时,我得到:

$ rake db:create
rake aborted!
LoadError: dlopen(/Users/mdurrant/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.20/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.20.dylib
  Referenced from: /Users/mdurrant/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.20/mysql2/mysql2.bundle
  Reason: image not found - /Users/mdurrant/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-14/2.1.0-static/mysql2-0.3.20/mysql2/mysql2.bundle
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `block in require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/activesupport-3.2.22/lib/active_support/dependencies.rb:251:in `require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/mysql2-0.3.20/lib/mysql2.rb:31:in `<top (required)>'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/gems/bundler-1.10.6/lib/bundler.rb:134:in `require'
/Users/mdurrant/eq/lynx/config/application.rb:10:in `<top (required)>'
/Users/mdurrant/eq/lynx/Rakefile:10:in `require'
/Users/mdurrant/eq/lynx/Rakefile:10:in `<top (required)>'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/Users/mdurrant/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
14:18:13 mdurrant EQ-267 /Users/mdurrant/eq/lynx master
$ 

【问题讨论】:

    标签: mysql ruby-on-rails rake


    【解决方案1】:

    OS X 无法找到 libmysqlclient.18.dylib 库。为了使其可访问,我们可以执行以下操作:

    export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
    

    到您的 ~/.bash_profile,运行后不要忘记获取它:

    $ source ~/.bash_profile
    

    然后:

     sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
    

    【讨论】:

    • 为您的答案添加更多细节并对其进行格式化以使其更具可读性。
    【解决方案2】:

    解决办法是

    gem uninstall mysql2
    

    然后重新安装它

    bundle  # gem install mysql2 would also work
    

    这将重新编译并解析安装 mysql 5.7.9 后留下的引用。

    【讨论】:

    • 对于那些想知道这可能是什么原因的人-我的松散理解是,这与安装mysql2时创建本机扩展的事实有关current Ruby _version(参见堆栈跟踪中的gems/ruby-2.1.5/extensions?)。如果您随后更改 Ruby 版本而不重新安装 mysql2,则现有的 natives 扩展将无法找到该图像,因为它仍在旧的 Ruby 版本下。所以你应该在更改 ruby​​ 版本后重新安装mysql2。
    • 在解决了多次安装 mysql 的问题后适用于 Apple M1 2021
    猜你喜欢
    • 2019-05-04
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2011-09-17
    • 2021-06-15
    • 2016-01-05
    相关资源
    最近更新 更多