I'm getting the following error when I start rails server:
我在启动rails服务器时出现以下错误:
$ rails server
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require': dlopen(/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2- 0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-
0.2.6/lib/mysql2/mysql2.bundle
I've installed mysql2 with the following command after the rvm use ruby-1.9.2-p0 command:
在rvm使用ruby-1.9.2-p0命令后,我已经用以下命令安装了mysql2:
$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
I have mysql2 in my Gemfile as well as in the database.yml file and bundle install completes fine
在Gemfile和数据库中都有mysql2。yml文件和bundle安装完成良好
$ bundle show mysql2
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6
I understand the rails server error is due to it not knowing the mysql_config location on OSX, however on gem install I specified the correct location. Yet RVM's gem is not respecting that mysql_config location it seems.
我理解rails服务器错误是由于它不知道OSX上的mysql_config位置,但是在gem安装时,我指定了正确的位置。然而,RVM的gem并没有考虑mysql_config位置。
Anyone have a solution to this?
有人能解决这个问题吗?
9 个解决方案
#1
63
The problem comes from the mysql2 gem missing the dynamic library from MySQL.
问题来自于mysql2 gem丢失了MySQL的动态库。
A cleaner solution than install_name_tool ...
would need to update your DYLD_LIBRARY_PATH
to add MySQL libs to it. To do so, update your ~/.bash_profile
to add the MySQL library folder :
一个比install_name_tool更干净的解决方案…需要更新DYLD_LIBRARY_PATH来添加MySQL libs。要做到这一点,请更新您的~/。bash_profile添加MySQL库文件夹:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
出口DYLD_LIBRARY_PATH = " / usr /地方/ mysql / lib:$ DYLD_LIBRARY_PATH "
Note: You might want to update the MySQL location based on your install
注意:您可能希望根据安装更新MySQL位置
This should keep things clean but also ensure that any gem or code requiring MySQL dynamic libraries will find them.
这可以保持事物的整洁,但也可以确保任何需要MySQL动态库的gem或代码能够找到它们。
Reference : http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
参考:http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
Reference Update July 2012: A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:
参考更新2012年7月:OS X 10.8的改变使得上面的简单方法不那么优雅。如果设置该变量,每次运行setuid或setgid程序时,stderr上就会出现以下警告:
dyld: DYLD_ environment variables being ignored because main executable (...) is setuid or setgid
Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.
Ruby开发人员使用Phusion Passenger会每五秒在他们的控制台中看到这个消息。这真的很烦人,很快。
I have filed a bug with Apple. It’s also at OpenRadar.
我已经向苹果提交了一个漏洞。这也是在OpenRadar。
In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:
同时,还有第三种方法可以修复客户端库路径问题,不需要设置DYLD_LIBRARY_PATH(处理这个10.8问题)或使用install_name_tool破解.bundle文件:
$ brew install mysql
#2
22
I found the answer here: Mysql 5.5, Snow leopard and rails
我在这里找到了答案:Mysql 5.5、Snow leopard和rails
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
#3
8
On OS X 10.8 (Mountain Lion), the listed answers all have issues, as noted in the answers and comments.
在OS X 10.8 (Mountain Lion)中,列出的答案都有问题,如答案和评论所示。
- Setting
DYLD_LIBRARY_PATH
to include /usr/local/mysql/lib gives warnings from OS X and from brew - 将DYLD_LIBRARY_PATH设置为包含/usr/local/mysql/lib会从OS X和brew中发出警告
- Using
install_name_tool
to hack where the gem binary looks would need to be redone each time the gem is installed or upgraded. - 使用install_name_tool来破解在每次安装或升级gem时需要重做的gem二进制外观。
- Switch to
brew
's mysql may not work; and in any case I don't want to reconfigure an already-working installation - 切换到brew的mysql可能不能工作;无论如何,我不想重新配置一个已经在工作的安装
A simpler and robust solution IMHO is to put a link to the library in the default dynamic library search path, which conveniently includes /usr/local/lib
. That is:
一个简单而健壮的解决方案IMHO是在默认的动态库搜索路径中放置一个到库的链接,它方便地包含/usr/local/lib那就是:
ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib
#4
5
Bill,
比尔,
Frederic's answer will solve this problem, however you may have to change some of the items in the command depending on versions and how things are named on your system.
Frederic的答案将会解决这个问题,但是你可能需要根据不同的版本以及事物在你的系统中如何命名来改变命令中的一些条目。
For example, on the most recent version of mysql libmysqlclient.16.dylib is actually libmysqlclient.18.dylib. Try doing a:
例如,在mysql libmysqlclient.16的最新版本上。dylib实际上是libmysqlclient.18.dylib。试着做:
locate libmysqlclient.18.dylib
If that does not return the path you can go to:
如果它不返回路径,您可以访问:
/usr/local/{your-mysql}/lib
to find the file. Then just a PWD to find the correct directory for the command.
找到该文件。然后只需一个PWD就可以找到该命令的正确目录。
You will also need to determine what the actual package names of the rubies you have installed are. You can find this by using
您还需要确定您安装的红宝石的实际包名称。你可以通过使用找到它
rvm info
For example, my installation of 1.9.2 is ruby-1.9.2.p180, not ruby-1.9.2p0. This will need to be changed in Frederics command as well.
例如,我的安装1.9.2 ruby 1.9.2的。p180,不是ruby-1.9.2p0。这将需要更改frederic命令。
So, for me Frederic's command became for fixing the rvm rubies for 1.8.7 and 1.9.2, respectively:
所以,对于我来说,Frederic的命令分别是用1.8.7和1.9.2来修复rvm红宝石:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.8.7-p334/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
#5
3
below via: http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
下面通过:http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
Update July 2012:
2012年7月更新:
A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:
OS X 10.8的变化使上述简单方法变得不那么优雅。如果设置该变量,每次运行setuid或setgid程序时,stderr上就会出现以下警告:
dyld: DYLD_ environment variables being ignored because main executable (...) is setuid or setgid
Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.
Ruby开发人员使用Phusion Passenger会每五秒在他们的控制台中看到这个消息。这真的很烦人,很快。
I have filed a bug with Apple. It’s also at OpenRadar.
我已经向苹果提交了一个漏洞。这也是在OpenRadar。
In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:
同时,还有第三种方法可以修复客户端库路径问题,不需要设置DYLD_LIBRARY_PATH(处理这个10.8问题)或使用install_name_tool破解.bundle文件:
$ brew install mysql
#6
1
Mine was in a different location, I had to use:
我的位置在不同的地方,我必须使用:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle.
#7
0
Here is what I do (similar to others)
这是我所做的(和其他人类似)
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.10/lib/mysql2/mysql2.bundle
#8
0
I was stuck on this for a while and came to a different solution.
我被这个问题困扰了一段时间,然后找到了一个不同的解决方案。
Notice how the missing library is version 16:
请注意缺失的库是如何版本16的:
Library not loaded: libmysqlclient.16.dylib (LoadError)
图书馆不加载:libmysqlclient.16。dylib(LoadError)
Turns out I had version 20 of that library - libmysqlclient.20.dylib
结果显示,我有这个库的20个版本——libmysqlclient.20.dylib。
I correctly had gem 'mysql2'
in my Gemfile, but what I needed to do was uninstall the gem, gem uninstall mysql
(I had multiple versions of the gem installed) and then doing a new bundle install
to get just the version I needed of this library.
我在Gemfile中正确地安装了gem“mysql2”,但是我需要做的是卸载gem,卸载mysql(我安装了多个版本的gem),然后进行新的bundle安装,以获得我需要的这个库的版本。
After that it looked for - and found - the correct version of that lib.
在那之后,它寻找并发现了那个库的正确版本。
#9
0
Upgraded mysql to latest version and reinstall mysql2 gem works to me brew upgrade mysql
gem uninstall mysql2
gem install mysql2
升级mysql到最新版本并重新安装mysql2 gem工作到我的brew升级mysql gem卸载mysql2 gem安装mysql2。
BTW: My MySQL version is 5.7.18, mysql2 gem version is 0.4.5
顺便说一句:我的MySQL版本是5.7.18,mysql2 gem版本是0.4.5
#1
63
The problem comes from the mysql2 gem missing the dynamic library from MySQL.
问题来自于mysql2 gem丢失了MySQL的动态库。
A cleaner solution than install_name_tool ...
would need to update your DYLD_LIBRARY_PATH
to add MySQL libs to it. To do so, update your ~/.bash_profile
to add the MySQL library folder :
一个比install_name_tool更干净的解决方案…需要更新DYLD_LIBRARY_PATH来添加MySQL libs。要做到这一点,请更新您的~/。bash_profile添加MySQL库文件夹:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
出口DYLD_LIBRARY_PATH = " / usr /地方/ mysql / lib:$ DYLD_LIBRARY_PATH "
Note: You might want to update the MySQL location based on your install
注意:您可能希望根据安装更新MySQL位置
This should keep things clean but also ensure that any gem or code requiring MySQL dynamic libraries will find them.
这可以保持事物的整洁,但也可以确保任何需要MySQL动态库的gem或代码能够找到它们。
Reference : http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
参考:http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
Reference Update July 2012: A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:
参考更新2012年7月:OS X 10.8的改变使得上面的简单方法不那么优雅。如果设置该变量,每次运行setuid或setgid程序时,stderr上就会出现以下警告:
dyld: DYLD_ environment variables being ignored because main executable (...) is setuid or setgid
Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.
Ruby开发人员使用Phusion Passenger会每五秒在他们的控制台中看到这个消息。这真的很烦人,很快。
I have filed a bug with Apple. It’s also at OpenRadar.
我已经向苹果提交了一个漏洞。这也是在OpenRadar。
In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:
同时,还有第三种方法可以修复客户端库路径问题,不需要设置DYLD_LIBRARY_PATH(处理这个10.8问题)或使用install_name_tool破解.bundle文件:
$ brew install mysql
#2
22
I found the answer here: Mysql 5.5, Snow leopard and rails
我在这里找到了答案:Mysql 5.5、Snow leopard和rails
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
#3
8
On OS X 10.8 (Mountain Lion), the listed answers all have issues, as noted in the answers and comments.
在OS X 10.8 (Mountain Lion)中,列出的答案都有问题,如答案和评论所示。
- Setting
DYLD_LIBRARY_PATH
to include /usr/local/mysql/lib gives warnings from OS X and from brew - 将DYLD_LIBRARY_PATH设置为包含/usr/local/mysql/lib会从OS X和brew中发出警告
- Using
install_name_tool
to hack where the gem binary looks would need to be redone each time the gem is installed or upgraded. - 使用install_name_tool来破解在每次安装或升级gem时需要重做的gem二进制外观。
- Switch to
brew
's mysql may not work; and in any case I don't want to reconfigure an already-working installation - 切换到brew的mysql可能不能工作;无论如何,我不想重新配置一个已经在工作的安装
A simpler and robust solution IMHO is to put a link to the library in the default dynamic library search path, which conveniently includes /usr/local/lib
. That is:
一个简单而健壮的解决方案IMHO是在默认的动态库搜索路径中放置一个到库的链接,它方便地包含/usr/local/lib那就是:
ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib
#4
5
Bill,
比尔,
Frederic's answer will solve this problem, however you may have to change some of the items in the command depending on versions and how things are named on your system.
Frederic的答案将会解决这个问题,但是你可能需要根据不同的版本以及事物在你的系统中如何命名来改变命令中的一些条目。
For example, on the most recent version of mysql libmysqlclient.16.dylib is actually libmysqlclient.18.dylib. Try doing a:
例如,在mysql libmysqlclient.16的最新版本上。dylib实际上是libmysqlclient.18.dylib。试着做:
locate libmysqlclient.18.dylib
If that does not return the path you can go to:
如果它不返回路径,您可以访问:
/usr/local/{your-mysql}/lib
to find the file. Then just a PWD to find the correct directory for the command.
找到该文件。然后只需一个PWD就可以找到该命令的正确目录。
You will also need to determine what the actual package names of the rubies you have installed are. You can find this by using
您还需要确定您安装的红宝石的实际包名称。你可以通过使用找到它
rvm info
For example, my installation of 1.9.2 is ruby-1.9.2.p180, not ruby-1.9.2p0. This will need to be changed in Frederics command as well.
例如,我的安装1.9.2 ruby 1.9.2的。p180,不是ruby-1.9.2p0。这将需要更改frederic命令。
So, for me Frederic's command became for fixing the rvm rubies for 1.8.7 and 1.9.2, respectively:
所以,对于我来说,Frederic的命令分别是用1.8.7和1.9.2来修复rvm红宝石:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.8.7-p334/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
#5
3
below via: http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
下面通过:http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
Update July 2012:
2012年7月更新:
A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:
OS X 10.8的变化使上述简单方法变得不那么优雅。如果设置该变量,每次运行setuid或setgid程序时,stderr上就会出现以下警告:
dyld: DYLD_ environment variables being ignored because main executable (...) is setuid or setgid
Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.
Ruby开发人员使用Phusion Passenger会每五秒在他们的控制台中看到这个消息。这真的很烦人,很快。
I have filed a bug with Apple. It’s also at OpenRadar.
我已经向苹果提交了一个漏洞。这也是在OpenRadar。
In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:
同时,还有第三种方法可以修复客户端库路径问题,不需要设置DYLD_LIBRARY_PATH(处理这个10.8问题)或使用install_name_tool破解.bundle文件:
$ brew install mysql
#6
1
Mine was in a different location, I had to use:
我的位置在不同的地方,我必须使用:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle.
#7
0
Here is what I do (similar to others)
这是我所做的(和其他人类似)
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.10/lib/mysql2/mysql2.bundle
#8
0
I was stuck on this for a while and came to a different solution.
我被这个问题困扰了一段时间,然后找到了一个不同的解决方案。
Notice how the missing library is version 16:
请注意缺失的库是如何版本16的:
Library not loaded: libmysqlclient.16.dylib (LoadError)
图书馆不加载:libmysqlclient.16。dylib(LoadError)
Turns out I had version 20 of that library - libmysqlclient.20.dylib
结果显示,我有这个库的20个版本——libmysqlclient.20.dylib。
I correctly had gem 'mysql2'
in my Gemfile, but what I needed to do was uninstall the gem, gem uninstall mysql
(I had multiple versions of the gem installed) and then doing a new bundle install
to get just the version I needed of this library.
我在Gemfile中正确地安装了gem“mysql2”,但是我需要做的是卸载gem,卸载mysql(我安装了多个版本的gem),然后进行新的bundle安装,以获得我需要的这个库的版本。
After that it looked for - and found - the correct version of that lib.
在那之后,它寻找并发现了那个库的正确版本。
#9
0
Upgraded mysql to latest version and reinstall mysql2 gem works to me brew upgrade mysql
gem uninstall mysql2
gem install mysql2
升级mysql到最新版本并重新安装mysql2 gem工作到我的brew升级mysql gem卸载mysql2 gem安装mysql2。
BTW: My MySQL version is 5.7.18, mysql2 gem version is 0.4.5
顺便说一句:我的MySQL版本是5.7.18,mysql2 gem版本是0.4.5