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

发布于 2024-08-15 21:05:24 字数 1394 浏览 2 评论 0原文

我在尝试安装 Ruby mysql gem 驱动程序时遇到问题。

我最近升级到 Snow Leopard 并手动安装了 MySQL 的 Hivelogic。这一切似乎工作正常,因为我可以从命令行访问 mysql 并对数据库进行更改。

我的问题是,如果我现在使用,

rake db:migrate 

我会得到:

rake aborted!
uninitialized constant MysqlCompat::MysqlRes

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

现在看来我的 mysql gem 无法正常工作,因为我可以使用 Python 驱动程序(我编译的)从 Python 很好地访问 MySQL。因此,我尝试使用此站点中的以下命令重建 gem: http://techliberty.blogspot.com/,(顺便说一句,我使用的是最近的英特尔 MacBook Pro):

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

虽然我得到了文档没有定义:但它可以编译:

  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
  ...

我有点困惑,因为我的 mysql_config 位于正确的位置:

 /usr/local/mysql/bin/mysql_config

并且我已经删除了所有其他实例mysql gem,来自我的系统。

任何建议将不胜感激。非常感谢。

PS我看到了上一篇文章未初始化常量MysqlCompat::MysqlRes(使用mms2r gem) 但它似乎不适用于我的版本。

I've got a problem trying to install the Ruby mysql gem driver.

I recently upgraded to Snow Leopard and did the Hivelogic manual install of MySQL. This all seems to work fine as I can access mysql from the command line and make changes to the database.

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). 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):

  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:

 /usr/local/mysql/bin/mysql_config

And I have removed all other instances of the mysql gem, from my system.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

画尸师 2024-08-22 21:05:24

基本上问题是找不到动态库 libmysqlclient 。上述解决方案可以工作,但每次重建 gem 或安装新版本的 MySQL 时都需要重新应用它们。

另一种方法是将包含该库的 MySQL 目录添加到动态加载路径。将以下内容放入我的 .bashrc 文件中解决了问题:

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

Basically the problem is the the dynamic library libmysqlclient can't be found. 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.

An alternative approach is to add the MySQL directory containing the library to your dynamic load path. Putting the following in my .bashrc file solved the problem:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
酒儿 2024-08-22 21:05:24

经过几天的努力,我终于解决了这个问题。我所做的两件事使它起作用:

  1. 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"

我有点惊讶 #2 只被 Steven Chanin 提到。

我使用的是 Snow Leopard,并且只安装了 1 个 MySQL (x86_64) 5.5 和 1 个 ruby​​(与 Snow Leopard 预先打包)。

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
  2. export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

I'm a bit surprised that #2 was only mentioned by Steven Chanin.

I'm on Snow Leopard, and have only 1 MySQL (x86_64) 5.5, and 1 ruby (prepackaged with Snow Leopard) installed.

怪我闹别瞎闹 2024-08-22 21:05:24

好的,我终于解决了这个问题。

发生这种情况的原因是我安装了两个版本的 Ruby。

  1. 在安装 Snow Leopard 之前,我已经按照 HiveLogic 指南编译并安装了我自己的 Ruby 版本。
  2. 然后我升级到 Snow Leopard(它有自己的 Ruby 版本)。

这两个版本存在冲突,这意味着当我尝试使用正确的 ARCHFLAGS 安装 MySQL gem 时,系统会认为我使用的是不同版本的 Ruby。

修复非常简单:

  1. 删除 HiveLogic 版本的 Ruby (https://content.pivotal.io/blog/removing-old-ruby-source-installation-after-a-leopard-upgrade)
  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

一旦我完成了这一切,一切就都正常了。

OK, I've finally solved this problem.

The reason this was occurring was that I had two versions of Ruby installed.

  1. I had compiled and installed my own version of Ruby following the HiveLogic guidelines, pre my installation of Snow Leopard.
  2. I then upgraded to Snow Leopard (which has it's own version of 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.

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)
  2. Recompile the MySQL gem with the correct ARCHFLAGS:

    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.

感性 2024-08-22 21:05:24

嗯,我是新手。经过一段时间的挣扎,由于上述方法都不适合我,我认为问题是由于我的“mysql”是 64 位安装,而 ruby​​ 是 32 位。
使用这些命令检查

file `which mysql`
file `which ruby`

两者都应与 Mach-O 64 位可执行文件 x86_64 或 Mach-O 64 位可执行文件 i386 匹配。
我安装了 32 位 mysql,从源代码和 Rails 重新安装了 ruby​​,从那以后一切都工作得很好。
顺便说一句,我在豹上。

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.
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.
I installed a 32-bit mysql, reinstalled ruby from source and rails and things have been working flawlessly since.
I am on Leopard btw.

離人涙 2024-08-22 21:05:24

我已经应用了 hivelogic post 的说明,但有版本5.1.41< MySQL 的 /a>。对于 gem 安装,我做了两件事:

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

事情对我来说效果很好。

I have applied the instructions of hivelogic post but with version 5.1.41 of MySQL. 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.

心房的律动 2024-08-22 21:05:24

这里也有同样的问题;已经断断续续地与这个问题斗争了两个多星期了!

我不是 ROR 专家,但从其他找到解决方案的更有知识的人看来,问题似乎指向 Ruby Gem for mysql,显然,它在 Mac 上错误地安装了自身。

我将继续在 Ruby Forge 站点进行调查,看看是否有任何 Ruby Gem 专家可以纠正这个可怕的错误......我需要我的 Rails 工作!时间就是金钱!

所以我在 RubyForge Mysql 开发人员错误跟踪页面< /a>.

我当然希望他们能提供帮助,因为这正在削弱我当前的项目。

如果其他人可以在那里支持我的错误报告,也许它会得到更多关注;请插话!

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.

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! Time is money!

So I reported this bug over at the RubyForge Mysql developers bug tracking page.

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!

野の 2024-08-22 21:05:24

在绞尽脑汁解决这个问题之后,我也发现问题与安装的同一 mysql gem 版本的多个二进制文件有关。以下为我修复了它。

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

接下来,我在我的 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

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. 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.

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
陪你到最终 2024-08-22 21:05:24

这可能是Mysql版本问题。您应该安装最稳定的版本(MYSQL 5.1)。请参阅我的博客文章: http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

This can be a Mysql version problem. You should install the most stable version (MYSQL 5.1). See my blog post : http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/

吃颗糖壮壮胆 2024-08-22 21:05:24

您有可能按照上述说明操作,但忘记在重新安装 Mysql 之前杀死服务器。这不会使错误消息消失。这发生在我身上。

在这里尝试了所有不同的选项后,我尝试了以下操作:

ps 辅助 | grep 'mysql'

杀死[pid_number_for_mysql]

基本上,以艰难的方式杀死服务器。然后,重新启动服务器。

There is a chance that you followed the above instructions but forgot to kill the server before reinstalling 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 | grep 'mysql'

kill [pid_number_for_mysql]

Basically, kill the server.. the hard way. Then, restart the server.

波浪屿的海角声 2024-08-22 21:05:24

如果您使用的是 MySQL 5.5,则以下是使其适用于我们的步骤:

安装 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

使 mysql-2.8.1 与 mysql 5.5 一起使用的命令:

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

希望有帮助!

If you're using MySQL 5.5, these are the steps that made it work for us:

Command to install 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:

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

Hope that helps!

℉絮湮 2024-08-22 21:05:24

我在最后一天努力解决这个问题,终于弄清楚了。我正在运行雪豹并进行了全新的 Rails 和 mysql 安装。我让它工作的唯一方法是从 dmg (不是 macports)安装 64 位版本的 mysql,并在启动时按住“6”和“4”键以 64 位模式重新启动我的机器。然后我安装了 gem,将我的数据库主机设置为本地,它运行得非常好。

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. 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. Then I installed the gem, set my DB host to local and it worked like a champ.

那片花海 2024-08-22 21:05:24

一些问题与过时的或多个冲突的红宝石和宝石二元有关。我自己在尝试使用 ruby​​ 1.9 运行我的代码时,遇到了使用系统 ruby​​“透明地”编译 mysql gem 的问题。通过这个线程解决了问题后,一切都很顺利。

为了避免这些问题并记录在案,RVM 工具包可能非常方便:http://rvm.beginrescueend.com。它有助于正确管理多个 ruby​​ 版本,并且巧妙地管理所有版本的 gem,而无需为每个版本保留副本。

看来使用 RVM 可以帮助避免该线程中的几个问题。

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. 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. It helps in properly managing several ruby versions, and it cleverly manages gems for all versions without keeping a copy for each version.

It seems that the use of RVM can help in avoiding several of the issues in this thread.

逆光飞翔i 2024-08-22 21:05:24

如果有人将 rvm 与 ruby​​ 1.8.7 和 mysql x86(32 位版本)一起使用并遇到此问题。您会发现此链接很有帮助:http://rvm.beginrescueend.com/integration/databases/ .您需要在 x86_64 版本中安装 mysql,然后安装 mysql gem,并将 archflags 设置为 x86_64。原因是即使你尝试将 gem 安装为 x86 来匹配你的 mysql x86。然而 ruby​​ 版本是 64 位的。所以你真的需要三个都匹配:Ruby、mysql 和 mysql gem。所以更简单的方法是将它们全部设为 64 位。

In case someone is using rvm with ruby 1.8.7 and mysql x86 (32 bits version) and have this issue. You will find this link helpful: 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. The reason is that even you try to install the gem as x86 to match your mysql x86. However the ruby version is in 64 bits. So you really need to have all three match: Ruby, mysql and mysql gem. So the easier way is to have all of them in 64 bits.

残花月 2024-08-22 21:05:24

对我来说非常快速的修复。

本周,在我一段时间没有使用的开发机器上,这个问题再次出现在我身上。根据 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

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:

sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
荒路情人 2024-08-22 21:05:24

我遇到了这个问题,或者至少有一个类似的问题(Hivelogic 没有涉及,它不是升级,而是一个新系统)。我同意这可能是 64 位问题。我有一个链接给你,在我做了那么多的头和屁股之后,终于救了我的屁股(和大脑)。

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

祝你好运,通过这个配置BS并进行一些编码。

I had this, or at least a similar, issue (Hivelogic was not involved and it was not an upgrade, but rather a new system). I agree that it is probably a 64 bit issue. 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]

Best of luck getting past this configuration BS and on to some coding.

垂暮老矣 2024-08-22 21:05:24

在寻找了很长时间来解决这个特定问题,并尝试了所有上述选项(以及许多其他站点上的选项)但没有运气后,我删除了 mysql-5.5 安装并安装了 mysql-5.1。突然之间,借助上面编译 64 位版本的一些帮助,我终于成功安装了一个可用的 mysql gem。

因此,如果您遇到此问题并且正在运行 mysql 5.5,请尝试降级到 mysql 5.1。

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. 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.

So, if you're running into this problem and are running mysql 5.5, try degrading to mysql 5.1.

油焖大侠 2024-08-22 21:05:24

我有同样的问题。我已将 mysql 安装在 /usr/local/mysql/current/ 中,而不是 /usr/local/mysql 中(在我的例子中,Snow Leopard 为 5.1.48 64 位)。但是,mysql客户端分片库(libmysqlclient.16.dylib)嵌入了 /usr/local/mysql/lib/libmysqlclient.16.dylib 路径。

在多次尝试使用 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

请注意,这是基于将 mysql 安装在 / usr/local/mysql/current,您需要编辑路径以适合您的系统。

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. However, the mysql client shard library (libmysqlclient.16.dylib) had a path of /usr/local/mysql/lib/libmysqlclient.16.dylib embedded in it.

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:

# 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文