简体   繁体   English

在Snow Leopard上安装mysql gem的问题:未初始化的常量MysqlCompat :: MysqlRes

[英]Problem installing mysql gem on Snow Leopard: uninitialized constant MysqlCompat::MysqlRes

I've got a problem trying to install the Ruby mysql gem driver. 我在尝试安装Ruby mysql gem驱动程序时遇到了问题。

I recently upgraded to Snow Leopard and did the Hivelogic manual install of MySQL. 我最近升级到Snow Leopard并完成了MySQL的Hivelogic手动安装。 This all seems to work fine as I can access mysql from the command line and make changes to the database. 这一切似乎工作正常,因为我可以从命令行访问mysql并对数据库进行更改。

My problem is that if I now use 我的问题是,如果我现在使用

rake db:migrate 

I get: 我明白了:

rake aborted!
uninitialized constant MysqlCompat::MysqlRes

(See full trace by running task with --trace)

Now it appears that my mysql gem isn't working correctly as I can access MySQL fine from Python using the Python driver (which I compiled to). 现在看来我的mysql gem工作不正常,因为我可以使用Python驱动程序(我编译到)从Python访问MySQL。 I therefore tried to rebuild the gem using the following command from this site: http://techliberty.blogspot.com/ , (incidentally I am using a recent Intel MacBook Pro): 因此,我尝试使用以下来自此站点的命令重建gem: http//techliberty.blogspot.com/ ,(顺便说一下,我使用的是最新的Intel MacBook Pro):

  sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

This compiles although I get No definition for the documentation: 这个编译虽然我得到没有文档的定义:

  Building native extensions.  This could take a while...
  Successfully installed mysql-2.8.1
  1 gem installed
  Installing ri documentation for mysql-2.8.1...

  No definition for next_result

  No definition for field_name
  ...

I'm a little stumped as my mysql_config is located in the correct place: 当我的mysql_config位于正确的位置时,我有点难过:

 /usr/local/mysql/bin/mysql_config

And I have removed all other instances of the mysql gem, from my system. 我从我的系统中删除了mysql gem的所有其他实例。

Any suggestions would be greatly appreciated. 任何建议将不胜感激。 Many thanks. 非常感谢。

PS I saw this previous post uninitialized constant MysqlCompat::MysqlRes (using mms2r gem) but it doesn't seem applicable for my version. PS我看到这个上一篇文章未初始化的常量MysqlCompat :: MysqlRes(使用mms2r gem),但它似乎不适用于我的版本。

Basically the problem is the the dynamic library libmysqlclient can't be found. 基本上问题是无法找到动态库libmysqlclient。 The above solutions will work, but you need to reapply them any time you rebuild the gem, or when you install a new version of MySQL. 上述解决方案可行,但您需要在重建gem时或安装新版本的MySQL时重新应用它们。

An alternative approach is to add the MySQL directory containing the library to your dynamic load path. 另一种方法是将包含库的MySQL目录添加到动态加载路径中。 Putting the following in my .bashrc file solved the problem: 将以下内容放在我的.bashrc文件中解决了这个问题:

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

OK, I've finally solved this problem. 好的,我终于解决了这个问题。

The reason this was occurring was that I had two versions of Ruby installed. 发生这种情况的原因是我安装了两个版本的Ruby。

  1. I had compiled and installed my own version of Ruby following the HiveLogic guidelines, pre my installation of Snow Leopard. 在安装Snow Leopard之前,我按照HiveLogic指南编译并安装了我自己的Ruby版本。
  2. I then upgraded to Snow Leopard (which has it's own version of Ruby) 然后我升级到Snow Leopard(它拥有自己的Ruby版本)

These two versions conflicted and meant that when ever I tried to install the the MySQL gem with the correct ARCHFLAGS the system thought I was using a different version of Ruby. 这两个版本冲突,意味着当我尝试使用正确的ARCHFLAGS安装MySQL gem时,系统认为我使用的是不同版本的Ruby。

The fix was simple enough: 修复很简单:

  1. Remove the HiveLogic version of Ruby ( https://content.pivotal.io/blog/removing-old-ruby-source-installation-after-a-leopard-upgrade ) 删除HiveLogic版本的Ruby( https://content.pivotal.io/blog/removing-old-ruby-source-installation-after-a-leopard-upgrade
  2. Recompile the MySQL gem with the correct ARCHFLAGS: 使用正确的ARCHFLAGS重新编译MySQL gem:

    sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config sudo env ARCHFLAGS =“ - arch x86_64”gem install --no-rdoc --no-ri mysql - --with-mysql-config = / usr / local / mysql / bin / mysql_config

Once I had done this everything worked fine. 一旦我完成了这一切,一切正常。

After wrestling with this problem for several days I finally got it nailed. 经过几天摔跤这个问题后,我终于把它钉了起来。 2 things that I have done that made it work: 我做过的两件事让它发挥作用:

  1. sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config sudo env ARCHFLAGS =“ - arch x86_64” gem install --no-rdoc --no-ri mysql - --with-mysql-config = / usr / local / mysql / bin / mysql_config
  2. export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH" export DYLD_LIBRARY_PATH =“/ usr / local / mysql / lib:$ DYLD_LIBRARY_PATH”

I'm a bit surprised that #2 was only mentioned by Steven Chanin. 我有点惊讶#2只是史蒂文·钱宁提到的。

I'm on Snow Leopard, and have only 1 MySQL (x86_64) 5.5, and 1 ruby (prepackaged with Snow Leopard) installed. 我使用Snow Leopard,并且只安装了1个MySQL(x86_64)5.5和1个红宝石(预装了Snow Leopard)。

Well, I am a newbie. 好吧,我是新手。 After struggling for a while and since none of the above worked for me, I figured the problem was due to my "mysql" being a 64-bit installation while ruby was 32-bit. 经过一段时间的努力,因为以上都没有为我工作,我认为问题是由于我的“mysql”是64位安装而ruby是32位。 Check with these commands 检查这些命令

file `which mysql`
file `which ruby`

Both should match Mach-O 64-bit executable x86_64 or Mach-O 64-bit executable i386. 两者都应匹配Mach-O 64位可执行x86_64或Mach-O 64位可执行i386。 I installed a 32-bit mysql, reinstalled ruby from source and rails and things have been working flawlessly since. 我安装了一个32位的mysql,从源代码和rails中重新安装了ruby,从那以后一直运行得很完美。 I am on Leopard btw. 我在Leopard顺便说一下。

I have applied the instructions of hivelogic post but with version 5.1.41 of MySQL. 我已经应用了hivelogic post的说明,但是使用了MySQL 5.1.41版。 And for the gem installation I did 2 things: 对于宝石安装我做了两件事:

sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

And things worked great for me. 事情对我很有用。

Same problem here as well; 同样的问题也在这里; have been wrestling with this off and on for over two weeks! 已经和我一起摔跤了两个多星期!

I'm no ROR expert, but from other more knowledgeable people who found a solution, the problem seems to point the Ruby Gem for mysql which, apparently, incorrectly installs itself on the Mac. 我不是ROR专家,但是从其他知识渊博的人那里找到解决方案,问题似乎指向Ruby Gem for mysql,显然,它错误地安装在Mac上。

I will continue to investigate at the Ruby Forge site, and see if any Ruby Gem gurus can correct this horrible bug....I need my Rails working! 我将继续在Ruby Forge网站上进行调查,看看是否有任何Ruby Gem大师可以纠正这个可怕的bug ....我需要我的Rails工作! Time is money! 时间就是金钱!

So I reported this bug over at the RubyForge Mysql developers bug tracking page . 所以我在RubyForge Mysql开发人员错误跟踪页面上报告了这个错误。

I sure hope they can help, as this is crippling my current project. 我当然希望他们可以提供帮助,因为这会削弱我目前的项目。

And if anyone else can support my bug report over there, perhaps it will get more attention; 如果其他人可以在那里支持我的错误报告,也许会得到更多的关注; please chime in! 请进来!

After racking my head with the problem, I too found that the problem had to do with multiple binaries of the same mysql gem version installed. 在解决问题之后,我也发现问题与安装了相同mysql gem版本的多个二进制文件有关。 The following fixed it for me. 以下为我修好了。

gem uninstall mysql
Select gem to uninstall:
 1. mysql-2.8.1
 2. mysql-2.8.1
 3. All versions
> 3

Successfully uninstalled mysql-2.8.1
Successfully uninstalled mysql-2.8.1

Next, I recompiled the mysql gem from source on my Snow Leopard machine, and all was swell with the world. 接下来,我在Snow Leopard机器上从源代码重新编译了mysql gem,并且全世界都在膨胀。

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.46-osx10.6-x86_64/bin/mysql_config

This can be a Mysql version problem. 这可能是一个Mysql版本的问题。 You should install the most stable version (MYSQL 5.1). 您应该安装最稳定的版本(MYSQL 5.1)。 See my blog post : http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/ 请参阅我的博客文章: http//geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

If you're using MySQL 5.5, these are the steps that made it work for us: 如果您使用的是MySQL 5.5,那么这些步骤可以帮助我们:

Command to install mysql-2.8.1: 安装mysql-2.8.1的命令:

sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri  mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Command to make mysql-2.8.1 work with mysql 5.5: 使mysql-2.8.1与mysql 5.5一起工作的命令:

sudo ln -s ../mysql/lib/libmysqlclient.16.dylib libmysqlclient.16.dylib

Hope that helps! 希望有所帮助!

There is a chance that you followed the above instructions but forgot to kill the server before reinstalling Mysql. 您可能会按照上述说明操作但忘记在重新安装Mysql之前终止服务器。 This will not make the error message go away. 这不会使错误消息消失。 This happened to me. 这发生在我身上。

After trying out all the different options here, I tried the following: 在尝试了所有不同的选项后,我尝试了以下方法:

ps aux | ps aux | grep 'mysql' grep'mysql'

kill [pid_number_for_mysql] 杀[pid_number_for_mysql]

Basically, kill the server.. the hard way. 基本上,杀死服务器..艰难的方式。 Then, restart the server. 然后,重新启动服务器。

I worked pretty hard getting this resolved for the last day and I finally figured it out. 我努力工作让最后一天得到解决,我终于明白了。 I'm running snow leopard and did a fresh rails and mysql install. 我正在运行雪豹,并做了一个新的rails和mysql安装。 The only way I got this to work was to install the 64bit version of mysql from the dmg (not macports) and restart my machine in 64 bit mode by holding the "6" and "4" keys down while booting. 我使用它的唯一方法是从dmg(而不是macports)安装64位版本的mysql,并在启动时按住“6”和“4”键以64位模式重启我的机器。 Then I installed the gem, set my DB host to local and it worked like a champ. 然后我安装了gem,将我的数据库主机设置为本地,它就像一个冠军。

Several problems were related to obsolete or multiple conflicting binaries of rubies and gems. 有些问题与过时的或多个冲突的红宝石和宝石二进制文件有关。 I have myself had the problem to "transparently" compile the mysql gem with the system ruby, while trying to get my code run with ruby 1.9. 我自己有问题要“透明地”使用系统ruby编译mysql gem,同时尝试使用ruby 1.9运行我的代码。 After figuring out the problem thanks to this thread, everything went smoothly. 通过这个线程找出问题之后,一切进展顺利。

To avoid these issues and for the records, the RVM toolkit may be very handy: http://rvm.beginrescueend.com . 为了避免这些问题和记录,RVM工具包可能非常方便: http//rvm.beginrescueend.com It helps in properly managing several ruby versions, and it cleverly manages gems for all versions without keeping a copy for each version. 它有助于正确管理多个ruby版本,并且巧妙地管理所有版本的gem,而无需为每个版本保留副本。

It seems that the use of RVM can help in avoiding several of the issues in this thread. 似乎使用RVM可以帮助避免此线程中的几个问题。

In case someone is using rvm with ruby 1.8.7 and mysql x86 (32 bits version) and have this issue. 如果有人使用rvm与ruby 1.8.7和mysql x86(32位版本)并有此问题。 You will find this link helpful: http://rvm.beginrescueend.com/integration/databases/ . 您会发现此链接很有用: http//rvm.beginrescueend.com/integration/databases/ You will need to install mysql in x86_64 version and then install the mysql gem with the archflags set to x86_64. 您将需要在x86_64版本中安装mysql,然后安装mysql gem并将archflags设置为x86_64。 The reason is that even you try to install the gem as x86 to match your mysql x86. 原因是即使您尝试将gem安装为x86以匹配您的mysql x86。 However the ruby version is in 64 bits. 但是ruby版本是64位。 So you really need to have all three match: Ruby, mysql and mysql gem. 所以你真的需要三个匹配:Ruby,mysql和mysql gem。 So the easier way is to have all of them in 64 bits. 所以更简单的方法是将它们全部放在64位中。

Very quick fix for me. 非常快速的修复我。

This problem popped up on me again this week on a development machine I'd not used for sometime. 这个问题本周再次出现在我不习惯的开发机器上。 As per Step 2 of emson's initial response, it only required a recompiling of the MySQL gem with the correct ARCHFLAGS: 根据emson初始响应的第2步,它只需要使用正确的ARCHFLAGS重新编译MySQL gem:

sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I had this, or at least a similar, issue (Hivelogic was not involved and it was not an upgrade, but rather a new system). 我有这个,或者至少是一个类似的问题(Hivelogic没有参与,它不是升级,而是一个新系统)。 I agree that it is probably a 64 bit issue. 我同意这可能是64位问题。 I have a link for you, that after all the other head and butt scratching I did, finally saved my ass (and brain). 我有一个链接给你,在我做了所有其他头部和屁股刮伤之后,终于保存了我的屁股(和大脑)。

[http://forums.mysql.com/read.php?116,359591,359591] [http://forums.mysql.com/read.php?116,359591,359591]

Best of luck getting past this configuration BS and on to some coding. 祝你好运过这个配置BS并进行一些编码。

After searching for a long time on solving this particular problem, and trying out all of the above options (and the options on many other sites) without luck, I removed my mysql-5.5 install and installed mysql-5.1. 经过长时间搜索解决这个特定问题,并尝试了所有上述选项(以及许多其他网站上的选项)没有运气,我删除了我的mysql-5.5安装并安装了mysql-5.1。 All of a sudden, and with a bit of the above help for compiling 64 bit versions, I finally managed to install a working mysql gem. 突然之间,有了上述帮助编译64位版本,我终于设法安装了一个有效的mysql gem。

So, if you're running into this problem and are running mysql 5.5, try degrading to mysql 5.1. 因此,如果您遇到此问题并且正在运行mysql 5.5,请尝试降级到mysql 5.1。

I had the same issue. 我遇到过同样的问题。 I had installed mysql (in my case, 5.1.48 64-bit for Snow Leopard) in /usr/local/mysql/current/, not in /usr/local/mysql. 我在/ usr / local / mysql / current /中安装了mysql(在我的例子中,为Snow Leopard的5.1.48 64位),而不是在/ usr / local / mysql中。 However, the mysql client shard library (libmysqlclient.16.dylib) had a path of /usr/local/mysql/lib/libmysqlclient.16.dylib embedded in it. 但是,mysql客户端分片库(libmysqlclient.16.dylib)中嵌入了/usr/local/mysql/lib/libmysqlclient.16.dylib的路径。

After several abortive attempts to fix this using install_name_tool, what worked was to both change the path in the shared library as follows, and then rebuild the mysql 2.8.1 rubygem, specifying both my: 在几次使用install_name_tool修复此问题的中断尝试后,有效的方法是更改​​共享库中的路径,如下所示,然后重建mysql 2.8.1 ruby​​gem,同时指定my:

# change the path embedded in libmysqlclient.dylib
sudo install_name_tool -change /usr/local/mysql/lib/libmysqlclient.16.dylib  /usr/local/mysql/current/lib/libmysqlclient.16.dylib /usr/local/mysql/current/lib/libmysqlclient.16.dylib

# reinstall the mysql gem
sudo ARCHFLAGS="-arch i386 -arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local/mysql/current --with-mysql-config=/usr/local/mysql/current/bin/mysql_config

Note that this is based on having mysql installed in /usr/local/mysql/current, you'll need to edit the paths to be appropriate for your system. 请注意,这是基于在/ usr / local / mysql / current中安装了mysql,您需要编辑适合您系统的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM