Create a symlink for the libmysqlclient.18.dylib library - mysql

I have installed mysql through a pkg installer.
I am trying to start rails server and I am getting the following error.
Library not loaded: libmysqlclient.18.dylib (LoadError)
I am reading that a solution to that is to create a symlink like
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
There is no
/usr/local/mysql/lib/libmysqlclient.18.dylib
file only a
/usr/local/mysql/lib/libmysqlclient.20.dylib file.
I run
sudo find /usr/ -name libmysqlclient.18.dylib
and I can't find the libmysqlclient.18.dylib file.

I encountered a problem like this while setting up a new development environment. I had installed MySQL via homebrew, which gave me version 5.7.9 of MySQL, with the library version libmysqlclient.20.dylib.
In my case, I was setting up a python project. The requirements install failed because the python-MySQL connection piece was looking for libmysqlclient.18.dylib, which was nowhere to be found on my machine.
Downgrading to MySQL 5.6 solved the issue for me:
brew uninstall mysql
brew tap caskroom/versions
brew install mysql56
Now /usr/local/lib/libmysqlclient.18.dylib is present and everything's peachy.

The mysql2 gem which is most likely in your Rails environment is still looking for libmysqlclient.18.dylib (from what must have been a previous mysql install) but the library is no longer there because the recent manual install/upgrade replaced it with libmysqlclient.20.dylib.
The easy fix is to install again mysql2:
gem uninstall mysql2 && gem install mysql2
or better yet:
gem uninstall mysql2 && bundle, if you are on Bundler.

I did not have mysql installed through brew or gem, and was facing the same issue that it was looking for libmysqlclient.18.dylib instead of libmysqlclient.20.dylib. I tried everything mentioned here and at some other threads. Nothing worked. Finally, this worked for me:
pip install mysqlclient
It does not install libmysqlclient.18.dylib, but solves the library not installed and image not found errors.
Hope it helps someone!

Uninstall mysqlclient
Clear cache of your pip
Find folder in which pip wheel cache is stored for mysqlclient and delete it.
Reinstall mysqlclient
mac mojave OS cache will be in this folder: ~/Library/Caches/pip. Follow the steps below:
Find ~/Library/Caches/pips/wheels/ | grep mysql
Delete the file you got.
pip install mysqlclient

Related

Cannot Install "mysql gem" on MacOS Sierra

I am trying to install the mysql2 gem for one of my rails projects but I am getting an error. I run this command:
gem install mysql2
The error says:
ld: library not found for -lssl
However when I run:
brew install openssl
I get (which proves that I have the -lssl library):
Error: openssl-1.0.2f already installed
To install this version, first `brew unlink openssl`
And alternatively when I run (which proves I have mysql on my machine):
brew install mysql
I get:
Error: mysql-5.7.10 already installed
To install this version, first `brew unlink mysql`
Very lost and would love to solve this, thank you in advance. I am running brew version 1.0.4.
I am having the same problem on Mac OS Mojave.
The following worked for me. First – very important – I ran xcode and discovered it needed to install some crap again. Then I did
brew reinstall openssl
gem install mysql2 -v '0.4.5' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install
The second line is based on the answer here.
I solved the same issue on my MacOS Sierra by refreshing gems reference:
gem source -r https://rubygems.org/
gem source -a https://rubygems.org/

Error while installing json gem 'mkmf.rb can't find header files for ruby'

For context, it on a remote server which has a firewall. I'm setting up my environment through a proxy. I have ruby 1.8.7. When I try to gem install..
sudo gem install --http-proxy <host address>:<port> json
I get the following error:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/json-1.8.1 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
Since I was unsure what the problem is, I googled and found these
gem install: Failed to build gem native extension (can't find header files) - the instructions here seem to be specific to the gem being installed.
How to install json gem - Failed to build gem native extension This seems to be slightly different error.
Any hints? Thanks!
Modern era update, as stated by mimoralea:
In case that you are using ruby 2.0 or 2.2 (thanks #patrick-davey).
sudo apt-get install ruby2.0-dev
sudo apt-get install ruby2.2-dev
sudo apt-get install ruby2.3-dev
or, generic way:
sudo apt-get install ruby-dev
or
sudo apt-get install ruby`ruby -e 'puts RUBY_VERSION[/\d+\.\d+/]'`-dev
The first link you’ve posted is exactly your case: there is no ruby development environment installed. Development env is needed to compile ruby extensions, which are mostly written in C. Proxy has nothing to do with the problem: everything is downloaded fine, just compilation fails.
I would suggest you to install ruby-dev (ruby-devel for rpm-based distros) package onto you target machine.
gcc package might be needed as well.
Try:
$ sudo apt-get install ruby-dev
Or, for Redhat distro:
$ sudo yum install ruby-devel
Or, for [open]SuSE:
$ sudo zypper install ruby-devel
For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with
sudo xcode-select --install
sudo xcodebuild -license accept
The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
which on macOS 10.14 with Xcode 11 prints the non-existent path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:
sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
This should now correctly print
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
Likewise, gem install should work while that SDK is selected.
To switch back to the current Xcode SDK, use
sudo xcode-select --switch /Applications/Xcode.app
In case that you are using ruby 2.0 or 2.2 (thanks #patrick-davey) or 2.3 (thanks #juanitofatas).
sudo apt-get install ruby-dev
sudo apt-get install ruby2.0-dev
sudo apt-get install ruby2.2-dev
sudo apt-get install ruby2.3-dev
And you get the pattern here...
I also encountered this problem because I install Ruby on Ubuntu via brightbox, and I thought ruby-dev is the trunk of ruby. So I did not install. Install ruby2.3-dev fixes it:
sudo apt-get install ruby2.3-dev
For those who are getting this on Mac OS X you may need to run the following command to install the XCode command-line tools, even if you already have XCode installed:
sudo xcode-select --install
Also you must agree the terms and conditions of XCode by running the following command:
sudo xcodebuild -license
I had a similar problem using cygwin to run the following command:
$ gem install rerun
I solved it by installing the following cygwin packages:
ruby-devel
libffi-devel
gcc-core
gcc-g++
make
automake1.15
Most voted solution didn't work on my machine (linux mint 18.04).
After a careful look, i found that g++ was missing.
Solved with
sudo apt-get install g++
in case you use SUSE
sudo yast2 -i ruby-devel
Xcode 11 / macOS Catalina
On Xcode 11 / macOS Catalina, the header files are no longer in the old location and the old /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg file is no longer available.
Instead, the headers are now installed to the /usr/include directory of the current SDK path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
Most of this directory can be found by using the output of xcrun --show-sdk-path. And if you add this path to the CPATH environment variable, then build scripts (including those called via bundle) will generally be able to find it.
I resolved this by setting my CPATH in my .zshrc file:
export CPATH="$(xcrun --show-sdk-path)/usr/include"
After opening a new shell (or running source .zshrc), I no longer receive the error message mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h and the rubygems install properly.
Note on Building to Non-macOS Platforms
If you are building to non-macOS platforms, such as iOS/tvOS/watchOS, this change will attempt to include the macOS SDK in those platforms, causing build errors. To resolve, either don't set CPATH environment variable on login, or temporarily set it to blank when running xcodebuild like so:
CPATH="" xcodebuild --some-args
In Fedora 21 and up, you simply open a terminal and install the Ruby Development files as root.
dnf install ruby-devel
On Mac 10.14, the header files don't seem to be installed in the correct place. Rather than changing paths like the other fixes, I was able to just run this:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Follow the instructions and it resolved this problem for me.
You may need to install gcc after install ruby-devel
Xcode -> Preferences -> Locations
change Command Line Tools to Xcode 11.2.1
You need to install the entire ruby and not just the minimum package. The correct command to use is:
sudo apt install ruby-full
The following command will also not install a complete ruby:
sudo apt-get install ruby2.3-dev
For Ubuntu 18, after checking log file mentioned while install
Results logged to /var/canvas/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/nio4r-2.5.2/gem_make.out
with
less /var/canvas/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/nio4r-2.5.2/gem_make.out
I noticed that make is not found. So installed make by
sudo apt-get install make
everything worked.
I faced a similar issue on Xcode 12 with macOS 10.15 and cocoapods. Just make sure that the xcode-select command points to the SDK you want to build against. It should build without issues afterwards.
BEFORE you follow the tip from Joki's answer (below) and IF :
you have MacOS 10.14.6
at /Library/Developer/CommandLineTools/SDKs/ you have folders
MacOSX.sdk(symbolic), MacOSX10.14.sdk, MacOSX10.15.sdk
Move MacOSX10.15.sdk to anywhere (admin privileges needs)
Delete symbolic link (admin privileges needs)
At /Library/Developer/CommandLineTools/SDKs/ create another symbolic link now to MacOSX10.14.sdk folder using (admin privileges needs)
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk MacOSX.sdk
Now you can follow Joki's answer
WARNING!
If you move MacOSX10.15.sdk folder to /Library/Developer/CommandLineTools/SDKs/ again, the command
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
will show MacOSX10.15.sdk folder like default again, nowadays I dunno how to fix it! My suggestion, compress the folder and put the original folder until fix will be available.
macOS RubyMine Gem installation failure
My problem with this error message was when trying to install a Gem via RubyMine. It didn't like that I had changed the global Ruby version with rbenv, so I fixed it by changing back to the system default Ruby version with:
rbenv global system
and restarted RubyMine.
sudo apt-get --reinstall install ruby
try it for ubuntu 16.04

Can't Run my server in rails after upgrading to ubuntu 12.04

I just upgraded ubuntu from 11.10 to 12.04 and after that when I run my server inside my rails project I got this error
$ rails s
/usr/share/ruby-rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require':
libmysqlclient_r.so.16: cannot open shared object file: No such file or directory -
/usr/share/ruby-rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.11/lib/mysql2/mysql2.so (LoadError)
any help please?
Go to your project and follow the steps,
rvm gemset empty <gemset name>
gem install bundler
bundle install
It will solve your problem.
If that does not work, or if you are not using rvm, please use
gem uninstall mysql2
bundle install
from one of your mysql2-using Rails project's directory.
I followed Babak's instruction that he posted and it worked after a small change.
My system is Ubuntu 12.04 server and it has Ruby1.9.3 installed so I did this
sudo apt-get install mysql-server libmysqlclient-dev
Seems like the libmysqlclient16-dev is now renamed to libmysqlclient-dev in Ubuntu 12.04
Afterwards I ran
gem install mysql2
Well, I would suggest double checking the ruby and the rails version and make sure they are the same ones u created your project with. Maybe you have to change the version using rvm:
rvm use 'Version'
Maybe you can uninstall and reinstall the mysql packages again, also try installing:
sudo apt-get install mysql-client mysql-server libmysqlclient16-dev
or
sudo apt-get install mysql-client mysql-server libmysqlclient-dev
Also try uninstalling and reinstalling your mysql gem. This blog post had a solution for this error as well, although the error was cause at a different time.
For me nothing up there work. Then I found this and try to delete and create again the database.yml file. AND IT WORKS!

Error installing mysql2: Failed to build gem native extension

I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysql2 it gives me the following error:
Error installing mysql2: ERROR: Failed to build gem native extension.
How can I fix this and successfully install mysql2?
On Ubuntu/Debian and other distributions using aptitude:
sudo apt-get install libmysql-ruby libmysqlclient-dev
Package libmysql-ruby has been phased out and replaced by ruby-mysql. This is where I found the solution.
If the above command doesn't work because libmysql-ruby cannot be found, the following should be sufficient:
sudo apt-get install libmysqlclient-dev
On Red Hat/CentOS and other distributions using yum:
sudo yum install mysql-devel
On Mac OS X with Homebrew:
brew install mysql
I'm on a mac and use homebrew to install open source programs. I did have to install mac Dev tools in order to install homebrew, but after that it was a simple:
brew install mysql
to install mysql. I haven't had a mysql gem problem since.
here is a solution for the windows users, hope it helps!
Using MySQL with Rails 3 on Windows
Install railsinstaller -> www.railsinstaller.org (I installed it to c:\Rails)
Install MySQL (I used MySQL 5.5) -> dev.mysql.com/downloads/installer/
--- for mySQL installation ---
If you dont already have these two files installed you might need them to get your MySQL going
vcredist_x86.exe -> http://www.microsoft.com/download/en/details.aspx?id=5555
dotNetFx40_Full_x86_x64.exe -> http://www.microsoft.com/download/en/details.aspx?id=17718
Use default install
Developer Machine
-MySQL Server Config-
port: 3306
windows service name: MySQL55
mysql root pass: root (you can change this later)
(username: root)
-MySQL Server Config-
--- for mySQL installation ---
--- Install the mysql2 Gem ---
Important: Do this with Git Bash Command Line(this was installed with railsinstaller) -> start/Git Bash
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"'
Now the gem should have installed correctly
Lastly copy the libmysql.dll file from
C:\Program Files\MySQL\MySQL Server 5.5\lib
to
C:\Rails\Ruby1.9.2\bin
--- Install the mysql2 Gem ---
You will now be able to use your Rails app with MySQL, if you are not sure how to create a Rails 3 app with MySQL read on...
--- Get a Rails 3 app going with MySQL ---
Open command prompt(not Git Bash) -> start/cmd
Navigate to your folder (c:\Sites)
Create new rails app
rails new world
Delete the file c:\Sites\world\public\index.html
Edit the file c:\Sites\world\config\routes.rb
add this line -> root :to => 'cities#index'
Open command prompt (generate views and controllers)
rails generate scaffold city ID:integer Name:string CountryCode:string District:string Population:integer
Edit the file c:\Sites\world\app\models\city.rb to look like this
class City < ActiveRecord::Base
set_table_name "city"
end
Edit the file c:\Sites\world\config\database.yml to look like this
development:
adapter: mysql2
encoding: utf8
database: world
pool: 5
username: root
password: root
socket: /tmp/mysql.sock
add to gemfile
gem 'mysql2'
Open command prompt windows cmd, not Git Bash(run your app!)
Navigate to your app folder (c:\Sites\world)
rails s
Open your browser here -> http://localhost:3000
--- Get a Rails 3 app going with MySQL ---
For MacOS Mojave:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
On Ubuntu(18.04)
i was able to solve this issue by running the following:
sudo apt-get install build-essential libmysqlclient-dev
gem install mysql2
reference
Another way for MacOS users
If you used "brew" to install mysql:
gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
x.x.x = version of the mysql2 gem you want to install
y.y.y = the version of mysql you have installed ls /usr/local/Cellar/mysql to find it.
I have several computers, 32 and 64 bits processor, they run on Ubuntu Linux, Maverick (10.10) release.
I had the same problem, and for me, the
sudo apt-get install libmysql-ruby libmysqlclient-dev
did the job!!!
Have you tried using
gem install mysql -- --with-mysql-lib=/usr/lib/mysql/lib
to specify the location of thebase directory as well as the path to the MySQL libraries that are necessary to complete the gem installation?
Sources:
MySQL Gem Install ERROR: Failed to build gem native extension
MySQL Forums :: Ruby :: Help needed with installing MySQL binding for Ruby
If you are using yum try:
sudo yum install mysql-devel
This solved my problem once in Windows:
subst X: "C:\Program files\MySQL\MySQL Server 5.5"
gem install mysql2 -v 0.x.x --platform=ruby -- --with-mysql-dir=X: --with-mysql-lib=X:\lib\opt
subst X: /D
On Debian Stretch the package that worked for me was default-libmysqlclient-dev
sudo apt-get update && apt-get install -y default-libmysqlclient-dev
If you are still having trouble….
Try installing
sudo apt-get install ruby1.9.1-dev
In my case this helped:
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
Then:
gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
Result:
Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib'
This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Installing ri documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 0 seconds
1 gem installed
See this post (WARNING: Japanese language inside).
I had this issue on Windows 7. This is apparently an incompatibility issue and the solution is as follows:
Download the libmySQL.dll file from an older InstantRails installer. It is available from the InstantRails GitHub repo.
Next, copy that file into your Ruby/bin folder.
Now, you are good to go ;)
I got this error too. Solved by installing development packages. I'm using arch and it was:
sudo pacman -S base-devel
which installed:
m4, autoconf, automake, bison, fakeroot, flex, libmpc, ppl, cloog-ppl, elfutils, gcc,
libtool, make, patch, pkg-config
but I think it actually needed make and gcc. Error output said (on my machine, among other):
"You have to install development tools first."
So it was an obvious decision and it helped.
You have to Install some dependencies
sudo apt-get install libmysql-ruby libmysqlclient-dev
I can see most of the people have found the solution to this problem, this is mostly coused but not limited to missing packages, this happened to me after I have purged mysql and reinstalled it. I had to run this command in order to fix my problem:
sudo apt-get install libmysqlclient-dev
This command helped me fix my problem
I was running into this error on my mac and found that I needed to upgrade from mysql 32bit to mysql 64 bit to get this error to go away. I was running OSX 10.6 on an intel macbook pro with ruby 1.9.2 and rails3.0.0
I also needed to install xcode in order to get unix utilities like "make" that are required to compile the gem.
once this was done I was able to run gem install mysql and gem install mysql2 without error.
I got the gem built on Mac OS X 10.6.6 by
1) Ensuring the Developer tools package is installed
2) Downloading the current MySQL package (5.5.8 in my case) from Source
3) Installing the cmake tool from cmake.org
4) Following the instructions in section 2.11 of INSTALL-SOURCE from the mysql distribution files
5) sudo gem install mysql2 -- --srcdir=/usr/local/mysql/include
The gem built successfully, but there are two errors in the documentation that rdoc and ri complain about.
But now when I try to require 'mysql2' I get a
LoadError: no such file to load -- mysql2/mysql2
I was hoping the error I would get was that the libmysqlclient.16.dylib couldn't be found because we figured that out in another post (search for install_name_tool).
My $PATH has /usr/local/mysql in it (that's where my source and built files are located), so I'm a little stumped. If anyone has any thoughts, I'll check back after a few hours of sleep.
For windows user:
You set the lib and include path of your mysql, for instance, if youre using xampp you can have like this:
gem install mysql2 -- '--with-mysql-lib="C:\xampp\mysql\lib" --withmysql-include="C:\xampp\mysql\include"'
Solution only works on Mac OS X
If you've installed MySQL with homebrew, what worked for me was uninstalling MySQL, and installing MySQL Community Edition via the MySQL website (https://www.mysql.com/).
After installed, just re-enter the command to gem install mysql2 or if necessary, sudo gem install mysql2, if you are getting permission denied problems.
If still getting error then follow the steps of mysql2 gem installation on Rails 3 on -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
where most of the user were able to install mysql2 gem.
After you get the mysql-dev issues corrected, you may need to remove the bad mysql2 install. Look carefully at the messages after $ bundle install. You may need to
rm -rf vendor/cache/
rm -rf ./Zentest
This will clear out the bad mysql2 installation so that a final $ bundle install can create a good one.
download the right version of mysqllib.dll then copy it to ruby bin really works for me. Follow this link plases mysql2 gem compiled for wrong mysql client library
Got the "You have to install development tools first." error when trying to install the mysql2 gem after upgrading to Mac OS X Mountain Lion. Apparently doing this upgrade removes the command line compilers.
To fix:
I uninstalled my very old version of Xcode (ran the uninstall script in /Developer/Library). Then deleted the /Developer directory.
Went to the AppStore and downloaded Xcode.
Launched Xcode and went into the Preferences -> Downloads, and installed the command line tools.
You are getting this problem because you have not install MySql. Before install mysql2 gem. Install MySQL. After that mysql2 gem will install.
I just wanted to add this answer specifically for Mac Users.
My server was running perfectly fine until I updated my xcode. The while starting my rails server the error was shown like this
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/user/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb --with-mysql-
checking for rb_thread_blocking_region()... /Users/user/.rvm/rubies/ruby-1.9.3-
p448/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an
executable file. (RuntimeError)
And there was suggestion to install mysql2 gem at the end of the error message. So when i tried installing it I got the error as above mentioned in this question. The error I got is as follows
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
So as suggested in this post I tried 'brew install mysql' and that quitted saying that mysql version so and so already installed. But there was warning before it saying
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:
xcodebuild -license
Then I tried this sudo xcodebuild -license and type 'agree' at the end. You have to be root to agree to the license.
After this, I again tried bundle install and then everything is working fine as normal. [ Even due to this xcode updation, I had problem with my tower also.]
libmysql-ruby has been phased out and replaced. New command:
sudo apt-get install ruby-mysql libmysqlclient-dev
Under ubuntu 20.04 LTS it's the only solution that have been working for me:
sudo apt-get install ruby-mysql2
According to https://github.com/brianmario/mysql2/issues/1175 , I fixed it by
gem install mysql2 -- \
--with-mysql-lib=/usr/local/Cellar/mysql/8.0.26/lib \
--with-mysql-dir=/usr/local/Cellar/mysql/8.0.26 \
--with-mysql-config=/usr/local/Cellar/mysql/8.0.26/bin/mysql_config \
--with-mysql-include=/usr/local/Cellar/mysql/8.0.26/include

Rails, MySQL and Snow Leopard

I upgraded to Snow Leopard using the disc we got at WWDC.
Trying to run some of my rails apps now complains about sql
(in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/
-- AdirondackPeepers.caf
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
(See full trace by running task with --trace)
I could have sworn I fixed this once before. The problem is that
sudo gem install mysql
does not work and gives the error:
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.
/opt/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
Has anybody gotten mysql to work with rails on snow leopard yet? If so, what is your setup and better yet, what can I do to reproduce it?
I just went through the same pain... here's what worked for me:
Download / install the 64-bit MySQL 5.1.37 from mysql.com
run the following commands:
sudo gem update --system
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I also uninstalled all mysql gems that were floating around from my 10.5 days, that may do it if the above doesn't work for you :)
Rebuilding mysql as 64bit or installing the 64bit version is important, but you also need to make sure you build the native parts of the mysql gem as 64bit as well (this doesn't apply if you are on one of the original Intel Core Duo macs).
Here's the magic command:
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
You should set the ARCHFLAGS as shown above whenever you do a gem install with native components on Snow Leopard.
If you're using bundler, you can use "bundle config" to set the proper build arguments for mysql like so:
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
I fought with this for a long time and finally got it working on Snow Leopard. I ended up installing Ruby, RubyGems, and MySQL from source (see the Hivelogic tutorial for installing Ruby and RubyGems. The MySQL tutorial is linked at the bottom). I finally got the gem to install, but I was still getting
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_init
Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Expected in: flat namespace
Trace/BPT trap
I finally deleted the mysql.bundle (I have no idea what this is for) and it all worked.
sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
Hope that helps someone.
I have seen this problem many times. almost everytime I build mysql on a machine. I think, you have to pass your mysqlconfig as part of the gem install command.
sudo gem install mysql -- --with-mysql-config=/your/mysql/config
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-mysql-config
Remember that you need mysql dev files to be able to build this gem.
I was having problems with getting my configuration to work after installing snow leopard. I found MAMP at http://www.mamp.info and it bundles Apache, PHP and MySQL. you install it like an application and it just works. Maybe worth giving it a try, and it is free.
mesh
I thought I would answer my own question here. It seems as if the problem isnt in mysql, but in the mysql ruby bindings. I figured this out because when I hooked up Querius (my mysql gui), it was able to connect.
Here is how to build from source fix the bindings:
cd /tmp
wget http://www.tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz
tar xvfz ruby-mysql-0.2.6.tar.gz
cd ruby-mysql-0.2.6
./configure
make
sudo make install
There are plenty of libraries that I will have to build from source on Snow Leopard and they keep popping up. MacPorts doesnt seem to be updated enough for all the libs so I'm off to do it on my own. Next up: freetype (http://download.savannah.gnu.org/releases-noredirect/freetype/)
I proceeded like explained in this post (http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/), and everything now works fine.
Remember to lookout for the typos in his command to install the mysql driver.
I had this same issue and here is what worked for me.
Install Snow Leopard and the 64bit MySQL DMG.
Create /etc/my.cnf to point to my previous MySQL data directory (as described here) and run sudo mysql_upgrade.
Opened IRB and reinstall all of my gems using (via blog.costan.us/2009/07/rebuild-your-ruby-gems-if-you-update-to.html).`gem list`.each_line {|line| system 'sudo gem install #{line.split.first}'}
Uninstalled the MySQL gems I had installed.
Installed MySQL gem with sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
With that, everything seems to be working so far. *knock wood*
In case you prefer homebrew, instead of installing MySQL manually.
Un-install the existing mysql gem (if any):
sudo gem uninstall mysql
Locate the ‘mysql_config’ file:
find /usr -name 'mysql_config'
Re-install mysql gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/bin/mysql_config
Note: replace /usr/local/bin/ with the corresponding mysql_config path found in step 2. Also on my blog.
Ian Selby thank you alot but I had to remove the sudo from in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.
I've solved it this way:
after install dmg file of mysql
bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
env ARCHFLAGS="-arch x86_64"
bundle install
Having had a break from Rails for several years, I just spent some time setting up my development environment. So thought I would create a tutorial on how to install the latest version of Rails 3, MySQL, and RVM on SnowLeopard, to hopefully save others some time who are in my position.
It works as of 21st August 2011, using Rails 3.0.10, MySQL 5.5.15, and RVM 1.7.2. It should work with future Rails 3.0.x, MySQL 5.5.x, and RVM 1.7.x versions.
Install XCode if not already installed. I used 4.0.2. Unfortunately this has now been withdrawn by Apple, but may be available elsewhere on the Internet. Version 3.2.x is free to download from Apple, but I did not test it with this tutorial, it probably works too.
Install rvm:
user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
user$ source .bash_profile
Install a version of Ruby (e.g. 1.9.2) in rvm, basic usage instructions are here.
user$ rvm install 1.9.2
user$ rvm use 1.9.2
Create a gemset for the rvm ruby installed in step 2 (x is the version number).
user$ rvm gemset create rails30x
user$ rvm 1.9.2#rails30x
Install Rails 3.0.x (x is the version number).
user$ gem install rails -v 3.0.x.
Download and install the MySQL 5.5.x package, the startup item, and the preferences pane. All 3 of these are included in the DMG install file. Also install MySQL WorkBench.
Find /usr/local/mysql-version-name/support-files (inserting the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46 locate the lines that read:
basedir=
datadir=
and change them to read (inserting the correct MySQL directory name):
basedir=/usr/local/mysql-version-name
datadir=/usr/local/mysql-version-name/data
Save the file. MySQL can now be started from the preferences pane.
To enable rails 3 to use mysql, install the mysql2 gem (see next step). First, you’ll need to set the
DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile in your
home folder and include the following (inserting the correct MySQL directory name):
export DYLD_LIBRARY_PATH=/usr/local/mysql-version-name/lib:$DYLD_LIBRARY_PATH
Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library
would appear and the server would abort.
Install the mysql2 gem. (as of May 2011, version 0.2.7 is the most recent working version with Rails 3.0.x).
user$ gem install mysql2 -v 0.2.7
Create a rails app, and it's corresponding database (appname_development).
user$ rails new appname
Add this to the app's Gemfile: gem 'mysql2', "0.2.7"
Add this to the app's database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: appname_development
pool: 5
username: username
password: pwd
host: localhost
start app and check "About your application's environment". Everything should be working correctly.
The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:
DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
to my bash profile, and this solved it for me.
I tried the archflags trick many times with slight variations but it never worked for me.
What finally did work was switching back to the version of ruby and gem installed with snow leopard.
I had built and installed my own version which has worked for me in every respect except this one.
Since everything else seems to work fine, I can't help guessing the mysql plugin has some funky assumptions in it. Anyway, all I did was switch /usr/bin to be first in my path again. I had installed ruby in /usr/local/ruby-1.8.7 and /usr/local/ruby-1.9.1 to be able to easily switch. Thought I'd mention it since the archflags solution seems to work for many people, but not quite all.
I renamed the mysql_config program from $MYSQL_HOME/bin to something else so that the configuration script from the gem installer is unable to find it. Even though I was using the libs option, the gem installer did always use the compile settings from my mysql installation, which is fat binary. But the default ruby installation is only x86_64 and therefore the compile of the gem fails. After renaming the mysql_config program the following command worked just fine and installed the gem:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql
If you are installing the mysql gem with RVM you need to use the following code to install it
sudo env ARCHFLAGS="-arch x86_64" gem install mysql
This method worked for me in Leopard Server, none of the above worked
this article solved the issue for me :)
http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html
Prior to Leopard
sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
Leopard on a PPC machine:
sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Leopard on an Intel machine:
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Snow Leopard (only on Intel):
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config