_mysql_init not found when using DataMapper
Asked Answered
B

1

19

I have a simple MySQL table:

% mysql -u rampion dev -e 'describe person'
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | UNI | NULL    | auto_increment |
| uid   | varchar(256) | NO   | PRI | NULL    |                |
+-------+--------------+------+-----+---------+----------------+

And a simple DataMapper script I want to run:

# temp.rb
require 'rubygems'
require 'datamapper'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "mysql://rampion@localhost/dev")

class Person
  include DataMapper::Resource
  property :id,     Serial
  property :uid,    String
end

DataMapper.finalize

p Person.first_or_create(:uid => 'Steve')

But when I run it, I get dynamic linker errors:

% ruby temp.rb
~/.rvm/gems/ruby-1.8.7-p334/gems/dm-validations-1.0.2/lib/dm-validations.rb:33: warning: already initialized constant OrderedHash
DataObjects::URI.new with arguments is deprecated, use a Hash of URI components (~/.rvm/gems/ruby-1.8.7-p334/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:215:in `new') 
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: ~/.rvm/gems/ruby-1.8.7-p334/gems/do_mysql-0.10.12/lib/do_mysql/do_mysql.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: ~/.rvm/gems/ruby-1.8.7-p334/gems/do_mysql-0.10.12/lib/do_mysql/do_mysql.bundle
  Expected in: flat namespace

zsh: trace trap  ruby temp.rb

I have LD_LIBRARY_PATH set to /usr/local/mysql/lib, which is where I have MySQL installed, and it seems to have _mysql_init defined in there:

% grep '_mysql_init' $LD_LIBRARY_PATH/libmysqlclient.18.dylib
Binary file /usr/local/mysql/lib/libmysqlclient.18.dylib matches

I have no idea what I need to do to fix this.

Backfire answered 8/2, 2013 at 21:32 Comment(4)
hmmm... I recently had a different problem where I found I was running 32-bit ruby but gems were trying to install as 64-bit. I wonder if this was related.Backfire
I remember having a similar issue after updating the MySQL client libraries without updating/reinstalling the mysql2 gem. So, just to be sure, you could try to update the MySQL client libraries and, after that, try rebuilding your gem. Apparently, you have built your own version of MySQL; in case you are using a Debian based version of Linux, just do sudo aptitude reinstall libmysqlclient-dev; gem install mysql2.Belford
On OS X you may want to scrub RVM completely and reinstall it so you have 64-bit clean builds of everything. Usually this is easy, bundle install will get you back to where you want to be. Ideally you can bump from Ruby 1.8.7 as well.Sapota
Using gem pristine --all should rebuild the gems to match the current environment. You might want to run gem up to refresh the gem code to the last version that'd run on 1.8.7 to pull in fixes. I'd strongly recommend upgrading from 1.8.7 to at least 1.9.3-p551, which is the current/last of the 1.9 line. You'll gain speed and security patches/fixes. See rvm.io/rvm/upgrading about upgrading RVM to its latest rev; Keeping it up to date is a really good idea even if you're going to let Ruby lag.Zakaria
D
0

Seems like an issue with old versions of MySQL, shouldn't happen nowadays see https://github.com/brianmario/mysql2/issues/121

Donoho answered 1/4, 2022 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.