mysql gem 2.7: impossible to install - mysql

I'm trying to install the mysql gem v. 2.7 on MacOsX Snow Leopard.
I know a lot has been written about this, and I've read most of it.
If I do the following:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -v '2.7' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I get:
ERROR: While executing gem ... (TypeError)
can't dup NilClass
Instead, trying to install v 2.8 works fine:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
Installing RDoc documentation for mysql-2.8.1...
But then I get this error when trying to start my local server:
=> Booting WEBrick
=> Rails 2.3.6 application starting on http://0.0.0.0:3000
/Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant MysqlCompat::MysqlRes (NameError)
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/dependencies.rb:80:in `const_missing'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/mysql_adapter.rb:9:in `define_all_hashes_method!'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/mysql_adapter.rb:68:in `mysql_connection'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activerecord-2.3.6/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
from /Users/phishman/Sites/BlindDog/vendor/plugins/admin_data/lib/admin_data/settings.rb:65:in `initialize_defaults'
from /Users/phishman/Sites/BlindDog/vendor/plugins/admin_data/init.rb:36:in `evaluate_init_rb'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/rails/plugin.rb:158:in `evaluate_init_rb'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/rails/plugin.rb:154:in `evaluate_init_rb'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/rails/plugin.rb:48:in `load'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/rails/plugin/loader.rb:38:in `load_plugins'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/rails/plugin/loader.rb:37:in `each'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/rails/plugin/loader.rb:37:in `load_plugins'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/initializer.rb:369:in `load_plugins'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/initializer.rb:165:in `process'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/initializer.rb:113:in `send'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/initializer.rb:113:in `run'
from /Users/phishman/Sites/BlindDog/config/environment.rb:9
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/dependencies.rb:156:in `require'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/dependencies.rb:156:in `require'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/activesupport-2.3.6/lib/active_support/dependencies.rb:156:in `require'
from /Users/phishman/Sites/BlindDog/vendor/ruby/1.8/gems/rails-2.3.6/lib/commands/server.rb:84
from script/server:3:in `require'
from script/server:3
Can you help me? Please, I've been breaking my head on this for 2 days :(
MySQL I'm using is the dmg downloaded from mysql.com. I even tried to uninstall it and install mysql from macports but getting lots of errors, so I had to re-install from mysql.com

I just ran into this issue myself. Googling turned up not only this question (which didn't help me - this project isn't ready for Bundler, plus we're using RVM so sudo is out) but also IRC logs from when I asked the same question on the RVM IRC channel a year ago. (Hmm, this sounds familiar.)
If you don't feel like sifting through the IRC log, here's the summary: newer versions of Rubygems (e.g. 1.6.x, which RVM installs by default with ree-1.8.7, which is what we were using) don't play well with the mysql gem. Try this:
ree-1.8.7 $ rvm rubygems 1.5.2
Removing old Rubygems files...
Installing rubygems-1.5.2 for ree-1.8.7-2012.02 ...
Installation of rubygems completed successfully.
ree-1.8.7 $ env ARCHFLAGS="-arch x86_64" gem install mysql -v 2.7 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql-2.7
1 gem installed
Installing ri documentation for mysql-2.7...
Installing RDoc documentation for mysql-2.7...
ree-1.8.7 $
Works a treat.

Found the way to install mysql gem and make it work:
I installed rvm, istalled ruby 1.8.7 and made it the defualt ruby (instead of the system one), then I compiled and reinstalled all the gems using
sudo env ARCHFLAGS="-arch x86_64" bundle install
Now it works!

I just ran in to this problem myself; we have an app that's running on an older version of ruby and rails.
I am using:
rbenv
Mac OS - Mavericks
bundler
ruby ree-1.8.7-2010.02
I had to downgrade rubygems:
gem update --system 1.5.2
Then I could install mysql 2.7 (and everything else) with:
sudo env ARCHFLAGS="-arch x86_64" bundle install

Related

Installed mysql gem file and received error 'wrong number of arguments (4 for 0) (ArgumentError)'

I am trying to run the following ruby program
require 'rubygems'
require 'mysql'
db = Mysql.new('local','root','','')
st_qry = db.query("SELECT * FROM `notification` ORDER BY notification_id DESC ")
puts ("There were #{st_qry.num_rows} rows returned.")
When I execute this code through terminal I get the following error message:
joe.fleck$ ruby mysql_req.rb
mysql_req.rb:4:in `initialize': wrong number of arguments (4 for 0) (ArgumentError)
from mysql_req.rb:4:in `new'
from mysql_req.rb:4
I have no idea how to fix this. I had to install mysql by this command:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
because the ordinary command (sudo gem install mysql) would error and not install.
I have also tried uninstall and install mysql. I tried mysql2 and it errors out when I try to execute the program.
Does anyone know how to solve this?
MacBook Pro, OS X version 10.8.2
$ gem list
*** LOCAL GEMS ***
addressable (2.3.2)
builder (3.1.3)
childprocess (0.3.5)
cucumber (1.2.1)
diff-lcs (1.1.3)
fastercsv (1.5.5)
ffi (1.1.5)
gherkin (2.11.3)
json (1.7.5)
libwebsocket (0.1.5)
multi_json (1.3.6)
mysql (2.8.1)
pkg-config (1.1.4)
rb-appscript (0.6.1)
rubygems-update (1.8.24)
rubyzip (0.9.9)
safariwatir (0.4.0)
selenium-webdriver (2.25.0)
shoes (3.0.1)
watir-webdriver (0.6.1)

mysql doesn't seem to work with my new rails app

I can't seem to get mysql to work with my new rails app at all... terminal copy below:
Janes-MacBook-Pro:development janelee$ cd hellomysql
Janes-MacBook-Pro:hellomysql janelee$ rails server
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): no suitable image found. Did find: (LoadError)
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2.rb:9
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:68:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `each'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:66:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `each'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler/runtime.rb:55:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/bundler-1.0.22/lib/bundler.rb:122:in `require'
from /Users/janelee/Development/hellomysql/config/application.rb:7
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:53:in `require'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:53
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
from /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/railties-3.2.1/lib/rails/commands.rb:50
from script/rails:6:in `require'
from script/rails:6
Janes-MacBook-Pro:hellomysql janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): no suitable image found. Did find:
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
(See full trace by running task with --trace)
and I tried this too:
Janes-MacBook-Pro:hello janelee$ gem uninstall sqlite3
You have requested to uninstall the gem:
sqlite3-1.3.5
i18n-0.6.0 depends on [sqlite3 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] y
Successfully uninstalled sqlite3-1.3.5
Janes-MacBook-Pro:hello janelee$ ARCHFLAGS="-arch x86_32" sudo gem install sqlite3
Password:
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Janes-MacBook-Pro:hello janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found. Did find:
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle
(See full trace by running task with --trace)
and this:
Janes-MacBook-Pro:hello janelee$ gem uninstall sqlite3
You have requested to uninstall the gem:
sqlite3-1.3.5
i18n-0.6.0 depends on [sqlite3 (>= 0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn] y
Successfully uninstalled sqlite3-1.3.5
Janes-MacBook-Pro:hello janelee$ ARCHFLAGS="-arch x86_64" sudo gem install sqlite3
Building native extensions. This could take a while...
Successfully installed sqlite3-1.3.5
1 gem installed
Janes-MacBook-Pro:hello janelee$ rake db:migrate
rake aborted!
dlopen(/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found. Did find:
/Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - /Users/janelee/.rvm/gems/ruby-1.8.7-p174/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle
(See full trace by running task with --trace)
What else should I try before reinstall Lion?
Look into using Ruby Version Manager (called rvm) and then update Ruby. Try using ver 1.9 of ruby or higher. Don't reinstall your OS. If anything, remove rails, remove ruby. Install rvm, install ruby 1.9, install rails. If you follow that recipe, all should be well.
Configuring Rails to work with MySQL will happen through changing the file:
myappname/config/database.yml
Good information is here: How do I set MySQL as the default database in Rails 3?
... and here: Create a new Ruby on Rails application using MySQL instead of SQLite
Get used to looking at the Rails guides. Examples like this: http://guides.rubyonrails.org/getting_started.html#configuring-a-database are all you need to get going.

Ruby mysql2 gem compiled for wrong mysql client library version

After updating MySQL to 5.5 using apt-get, the mysql2 gem stopped working.
Here's the error:
Incorrect MySQL client library version!
This gem was compiled for 5.5.17 but the client library is 5.1.58. (RuntimeError)
I tried reinstalling with mysql_config but it doesn't seem to make a difference..
gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config
Correspondingly, I tried telling bundle to compile mysql2 with mysql-config but still, the error remains..
bundle config build.mysql2 --with-mysql-config=/usr/bin/mysql_config
bundle install
When I tried an older version of the gem (v0.2.6) the rails console opens but crashes once I run any type of query.
Here's the full error stack when trying the most current version of the mysql2 gem:
[marco#linode:/www] 07:29:00 AM: rails c
/users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in `require': Incorrect MySQL client library version! This gem was compiled for 5.5.17 but the client library is 5.1.58. (RuntimeError)
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/mysql2-0.3.10/lib/mysql2.rb:9:in `<top (required)>'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
from /www/config/application.rb:7:in `<top (required)>'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:38:in `require'
from /users/marco/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Edit: I removed all mysql2 gemspecs from cache, uninstalled all mysql-related packages via apt-get and reinstalled everything afresh, then tried again to install the gem with the mysql-config flag .. but it all proved futile. The error remains.
Edit 2: As suggested by John Bachir, I confirmed that mysql_config contains MySQL version 5.5.
Late to the party, but I just did
gem uninstall mysql2
gem install mysql2
Gem path was
$ bundle show mysql2
/var/lib/gems/1.9.1/gems/mysql2-0.3.16
I have encounter the same error when using Ubuntu Server 11.04 and Percona Server, what have I done was:
replace /usr/lib/libmysqlclient.so.16.0.0 with /usr/lib/libmysqlclient.so.18.0.0
I had this problem and just needed to recompile the gem. I don't know if there's a more programmatic way with bundler, but I just removed the compiled gem and then re-ran bundler:
$ bundle show mysql2
/usr/local/rvm/gems/ruby-1.9.3-p385/bundler/gems/mysql2-32dd7e5bbeba
$ rm -rf /usr/local/rvm/gems/ruby-1.9.3-p385/bundler/gems/mysql2-32dd7e5bbeba
$ bundle
I came across a similar problem:
Incorrect MySQL client library version! This gem was compiled for 5.6.12 but the client library is 5.5.28.
And my MySQL version on Mac:
$ mysql --version
mysql Ver 14.14 Distrib 5.6.12, for osx10.8 (x86_64) using EditLine wrapper
and the mysql2 gem installed by bundle install is mysql2-0.3.13
I solved this problem by just setting the mysql2 gem to an older version in the Gemfile:
gem 'mysql2', '0.2.6'
If '0.2.6' does not work for you, you could try another old version number.
Rather than moving library files, you might also check the package list for your system -- if you upgraded to 5.5 using apt-get, it's likely that you still have 5.1 libraries lying around that you don't need anymore at all. For example, on a system where we encountered a similar issue, we still had the 5.1 library:
$ sudo dpkg -l | grep mysql
ii libmysqlclient-dev 5.5.13-rel20.4-136.lucid Percona Server database development files
ii libmysqlclient16 5.1.61-rel13.2-431.lucid Percona Server database client library
ii libmysqlclient18 5.5.13-rel20.4-136.lucid Percona Server database client library
Rather than copying the 5.5 library over the 5.1 library, you should be able to remove it:
$ sudo apt-get remove libmysqlclient16
For us, this has been more reliable than the library renaming solution proposed earlier.
I meet this problem again and I could not solve it with my previous method(use an older version mysql2 gem). So I try another method as these step:
1.find which mysql_config that your gem library depend on.
mysql_config situation is different in different people's machine, and one people machine can have several mysql_config, so there is no standard mysql_config path for everyone.
As this question for example, the mysql_config version is "5.1.58", so you can search "mysql" file in root to find which has related with "5.1.58":
cd /
sudo find -name "mysql" ./
2.install mysql2 gem library again with specific mysql_config path find in step 1
gem install mysql2 -- --with-mysql-config=<%your_specific_mysql_config_path%>
Other than making sure that only the libmysqlclient18 library was installed (and not 16), what made it work for me was installing libmysqlclient18-dev (the dev headers).
This is with Percona Server 5.5 on Ubuntu Precise.
I tried all the answers above and my final approach was fairly simple -- delete the entire bundled gem stack and reinstall everything. That finally got around the mysql client issue. i.e.
rm -rf /Users/sjohnson/.rvm/gems/ruby-1.9.3-p484#adp_rails3
bundle install
if you know c program,you can remove this message. omit it.
open this mysql.gem mysql-2.9.1.gem\data.tar.gz\data.tar\ext\mysql_api\mysql.c
find "This gem was compiled for" ,delete this if sentence .
if (lib[i] != MYSQL_SERVER_VERSION[i]) { Line 1897: rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_SERVER_VERSION, lib); }
you need set sys-variable for local gemfile install on windows system . SET HOMEDRIVE=c:
ERROR: While executing gem ... (Errno::EINVAL) Invalid argument # rb_file_s_stat - U:/
install local gem file . C:\Rails>gem install --local mysql-2.9.1.gem --install-dir=c:/tmp --platform= ruby -- --with-mysql-dir=C:/Rails/mysql-connector-c
mysql-connector-c visit mysql http://dev.mysql.com/downloads/connector/c/ . you don't care version.
try again.
require 'mysql'
On Mac using Brew verify the versions installed on your machine:
ls /usr/local/Cellar/mysql*
Them remove the wrong version such as:
brew uninstall mysql-client
Remove the gem:
gem uninstall mysql2
Run bundle again:
bundle install
Make sure that /usr/bin/mysql_config is indeed the one that came with 5.5.
In my case, I had various files from libmysqlclient15 (dated 2009) and libmysqlclient16 (dated 20012) left in /usr/lib, possibly from a botched Ubuntu upgrade.
Removing the libmysqlclient15 files (which were linked to libmysqlclient15.so) solved my problem.
On my machine I had to uninstall the gem, then re-direct the symlink /usr/local/mysql to the correct Homebrew version:
ln -s /usr/local/bin/mysql /usr/local/mysql
Then run bundle install.
Reinstall libmysqlclient-dev with apt remove libmysqlclient-dev && apt install libmysqlclient-dev fixed for me
This is for anyone that stumble upons this question after 11 years.
Finally figured out that an update on mariadb-connector-c caused my rails fail to start up with a Bundler::GemRequireError.
It was complaining with the following:
Gem Load Error is: Incorrect MySQL client library version! This gem was compiled for 10.6.8-MariaDB but the client library is 3.2.7.
The version numbers that are suggested in the error are widely different, which felt strange. This wasn't a new install, my dev env was working for months.
After going through all sorts of hoops, depleting SO resources and even getting some AI involved, I finally tried downgrading the package. (My next step was going to be removing MariaDB altogether, but fortunately we didn't come to that)
sudo dnf downgrade mariadb-connector-c-3.1.13-2.fc35 --allowerasing
I verified that the mysql cc_version went down
/usr/bin/mysql_config
Then I removed and installed the gem
gem uninstall mysql2
gem install mysql2 -v '0.3.21' -- --with-mysql-config=/usr/bin/mysql_config
That's it. rails was working again.
FYI: I am on Fedora 35; I use RVM; and the rails version was 4.2
A couple of things that may fix some other people's issues:
Reinstalling Gem:
gem uninstall mysql2
gem pristine mysql2 or bundle install or gem install mysql2 -v '0.3.21' --source 'https://rubygems.org/'
Checking Package History:
dnf history provides a list of recent dnf changes... some have empty fields in "Command Line" column...
those still have updates, etc in them... you can refer to them with
dnf history info <ID>

version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1

Hi i am using rails version 3.0.7 when i run rails generate model task name:string i m getting following warning
WARNING: This version of mysql2 (0.3.2) doesn't ship with the ActiveRecord adapter bundled anymore as it's now part of Rails 3.1
WARNING: Please use the 0.2.x releases if you plan on using it in Rails <= 3.0.x
/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/railtie.rb:59
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.7/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.7/lib/active_record/base.rb:1904
from /home/sun/railsapp/dog/vendor/plugins/attribute_fu/init.rb:1
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/plugin.rb:81
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `instance_exec'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:25:in `run'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:50:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/initializable.rb:49:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:134:in `initialize!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `send'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
from /home/sun/railsapp/dog/config/environment.rb:5
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/application.rb:103:in `require_environment!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.0.7/lib/rails/commands.rb:16
from script/rails:6:in `require'
from script/rails:6
when i try to install activerecord-mysql2-adapter by :gem install activerecord-mysql2-adapter
ERROR: Could not find a valid gem 'activerecord-mysql2-adapter' (>= 0) in any repository
please help me
thanks
The problem is because you are trying to install the latest version of mysql2 which is incompatible with rails 3.0.x version
SO, in your Gemfile change the line for mysql2 gem for this:
gem 'mysql2', '< 0.3'
then bundle command
and then when the new mysql2 gem file ( i think is 0.2.7 ) you will solve the problem.
if still not working try this too:
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Users/YOUR_USER_NAME/.rvm/gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
gem 'mysql2', '< 0.3' is the only way on Rails 3.0.7 (before 3.1)
UPDATE: sorry, that was not the case also, did't work either, there is a better way:
vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.2/lib/active_record/connection_adapters$[rails307]$ ls
em_mysql2_adapter.rb mysql2_adapter.rb
take mysql2_adapter.rb file from mysql2 gem version 0.2.x and copy it to the above location
now it works for me with just gem 'mysql2' in Gemfile
After trying the solution offered by #eveevans I was still having version issues. Then reading the suggestion by #rubyconvict, I thought instead about using the -v option for gem rather than pushing files about.
Here's what I found eventually resolved my struggle with the dreaded "version of mysql2 (0.3.2)" message on DreamHost:
# in mysql, create example_app & example_app_test ...
# ... for the purposes of this example only, production == development db
rails new example_app --database=mysql --freeze
cd example_app
vim config/database.yml
# change settings for host, user, password ...
# ... database for test (example_app_test) ...
# ... & database for production & development (example_app)
vim Gemfile
# gem 'mysql2', '< 0.3'
gem uninstall mysql2 # if installed: gem list -d mysql2
gem install mysql2 -v 0.2.7
rake db:migrate
From there, I can move onto other RoR fun, like perhaps modifying routes (vim config/routes.rb ... however your mileage may vary).
WARNING: Please use the 0.2.x
releases if you plan on using it in
Rails <= 3.0.x
so in short just use the latest in the 0.2.x branch for the mysql2 gem.

Rails on Mac OS X Snow Leopard: mysql2.bundle dlsym - Symbol not found (LoadError)

Platform: Mac OS X (macosx) 10.6.6
Ruby: 1.9.2
Rails: 3.0.3
Using RVM
This is the error I am getting:
$ rails s
/Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlsym(0x13782a0, Init_mysql2): symbol not found - /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle (LoadError)
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.7/lib/mysql2.rb:8
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler/runtime.rb:68:in `require'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `each'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler/runtime.rb:66:in `require'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `each'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler/runtime.rb:55:in `require'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.13/lib/bundler.rb:120:in `require'
from /Users/nicolas/git/hits/config/application.rb:7
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/commands.rb:28:in `require'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/commands.rb:28
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/commands.rb:27:in `tap'
from /Users/nicolas/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.6/lib/rails/commands.rb:27
from script/rails:6:in `require'
from script/rails:6
This a very persistent error. Here is some more info, that may help resolve it:
I have upgraded from Leopard to Snow Leopard in the past.
I have tried bundle install.
I have tried erasing ~/.rvm and re-installing RVM
I have tried: env ARCHFLAGS="-arch x86_64" gem install mysql2 -v 0.2.7
I tried installing the latest mysql (mysql-5.5.12-osx10.6-x86_64.dmg) on top of whatever
mysql was there on my system before
Here is some more info about my system:
$ echo $DYLD_LIBRARY_PATH
/usr/local/mysql/lib:
$ file ~/.rvm/rubies/default/bin/ruby
/Users/nicolas/.rvm/rubies/default/bin/ruby: Mach-O 64-bit executable x86_64
$ file /usr/local/mysql/lib/libmysqlclient.18.dylib
/usr/local/mysql/lib/libmysqlclient.18.dylib: Mach-O 64-bit dynamically linked shared library x86_64
$ rvm list
rvm rubies
=> ruby-1.9.2-p180 [ x86_64 ]
$ which ruby
/opt/local/bin/ruby
$ file /opt/local/bin/ruby
/opt/local/bin/ruby: Mach-O executable i386
which ruby says that you're using not the RVM supplied ruby. After installing RVM and a ruby, you have to tell RVM to use it:
rvm use --default 1.9.2
If you haven't installed ruby on RVM yet then you have to install it before using:
rvm install 1.9.2
After that you will probably need to install rails again, as your current version is probably installed with the system ruby and not RVM.