MySQL Ruby Gem on OS X Snow Leopard - mysql

I've been fighting with getting the MySQL Ruby Gem up and running on Snow Leopard for the past couple of days.
I have tried all different sorts of things to get this working, and currently have MySQL 5.1.37 x64 installed. After fighting to even get the Gem installed I believe that I finally got it installed, but whenever I attempt to access my Rails site I immediately receive the following error:
/!\ FAILSAFE /!\ Tue Sep 01 21:47:23 -0500 2009
Status: 500 Internal Server Error
Client does not support authentication protocol requested by server; consider upgrading MySQL client
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:453:in `read'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/mysql.rb:130:in `real_connect'
The remote server I am attempting to connect to is running MySQL version 5.0.70, and can be connected to by other clients (including Sequel Pro running from my machine).
Here are some of the versions of software currently installed on my machine:
MySQL 5.1.37 OS X 10.5 x86-64
Ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
Gem version 1.3.5
I have read other accounts of people getting this working on Snow Leopard, so surely I've missed a step. Any advise would be greatly appreciated.
Thanks!

There's a post about this that basically says:
Compile it from source using: CC=gcc CFLAGS="-arch x86_64 -O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-arch x86_64 -O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=innobase && make && sudo make install
Install the mysql gem with: sudo env ARCHFLAGS="-arch x86\_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I did this and it works for me.

on the official weblog of ruby on rails they told something about leopard
http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard

Related

ThinkingSphinx::SphinxError (Unknown MySQL error)

I try to run gem 'thinking-sphinx' on my Ruby on Rails project, but something was wrong. When I run any search command on any model, I see this error: ThinkingSphinx::SphinxError (Unknown MySQL error).
More details:
MacOS Mojave -v 10.14.3
mysql -v 8.0.15 (Installed first)
Sphinx -v 2.2.11_2 (Installed via 'brew install sphinx')
thinking-sphinx -v 4.2.0
Rails -v 5.2.2
Before run search command, I runned rails ts:index and rails ts:start
What am I doing wrong?
Sphinx v2.2 (and 3.0) is not compatible with MySQL v8. You'll either want to downgrade MySQL to 5.7 - which can be done with homebrew via brew install mysql#5.7 - and then uninstall and reinstall Sphinx, or download the binaries for Sphinx v3.1.1 (the first version to support MySQL v8) from the Sphinx website (the source code for that release is not currently available, hence it's not installable via homebrew).
Just changed mysql2 from gem "mysql2", '~> 0.4.6' to gem "mysql2", '0.4.10' version, and it worked for me. Thanks

MySQL Gem failure: MysqlCompat::MysqlRes on Snow Leopard

I am trying to get the mysql gem to work ... and it just doesn't want to. Every time I do a rake db:migrate, I get
uninitialized constant MysqlCompat::MysqlRes
I've installed mysql from this disk image: mysql-5.5.9-osx10.6-x86_64.dmg
I've run the gem install with the infamous archflags setting:
sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
And the ruby version I'm using is the default from Snow Leopard:
[~/sites/testdb]$ file `which mysql`
/usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
[~/sites/testdb]$ file `which ruby`
/usr/bin/ruby: Mach-O universal binary with 3 architectures
/usr/bin/ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/ruby (for architecture i386): Mach-O executable i386
/usr/bin/ruby (for architecture ppc7400): Mach-O executable ppc
My database.yml is pretty simple:
development:
adapter: mysql
host: 127.0.0.1
database: testdb
username: root
password:
Any help would be appreciated.
You can easy fix your problem.
If you don't use rvm:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundleruby
If you use rvm:
install_name_tool -change libmysqlclient.16.dylib usr/local/mysql/lib/libmysqlclient.16.dylib [YOUR_GEMSET_PATH]/gems/mysql-2.8.1/lib/mysql_api.bundle
I blogged about this last week: MySQL 5.5 on Mac OS X.
My alternate solution to using install_name_tool is to set DYLD_LIBRARY_PATH in your shell startup files. The advantage to this you do it once, whereas if you use install_name_tool, you will repeat that every time to re-install or upgrade the gem.
The mysql2 gem will have the same problem with a slightly different error message. The problem is how the libmysqlclient library is built. It doesn't include a full path, so anything linking with it can't find it at runtime.
I ran into the same error. On my machine, though, the mysql gen was built when I still had mysql 5.1 on my machine. Now, after upgrading to MySQL 5.5, the dyld-file referred by the original build /usr/local/mysql/lib/libmysqlclient.16.dylib didn't exist any more and was replaced by a file /usr/local/mysql/lib/libmysqlclient.18.dylib.
Completely rebuilding the mysql gem fixed things, i.e.
gem uninstall mysql
gem install mysql
You could try using the mysql2 gem which may not suffer from the same problems.
I've found it's often a lot better to use ruby and mysql from MacPorts or brew to keep everything on the same page and not mess with the system Ruby.
OS X comes with a version of MySQL that may not match up with what you have installed, or perhaps the gem installer is confused about which config program to use. Make sure mysql_config is returning the correct path.

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

Cannot get mysql gem to work in Snow Leopard, unable to setup ruby on rails environment

I am having some serious problems, however this seems to be a common thing. I have Snow Leopard 10.6.3 and here are my other version info:
MySQL
mysql Ver 14.14 Distrib 5.1.46, for apple-darwin10.2.0 (i386) using readline 5.1
gem 1.3.6
ruby 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]
My problem is that no matter what I do to try and install the mysql gem, i still get the error every time i do rake db:migrate
uninitialized constant MysqlCompat::MysqlRes
I have installed the mysql gem based on instructions around the web that say to use
export ARCHFLAGS="-arch i386 -arch x86_64" ; sudo gem install --no-rdoc --no-ri mysql -- -v 2.7 --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/mysql/bin/mysql_config
This DOES work, as it gives this output:
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Any help would be greatly appreciated
These instructions worked great for me on Mac OS X Snow Leopard: http://hivelogic.com/articles/compiling-mysql-on-snow-leopard
if you've migrated to snow leopard from leopard, you may need to rebuild ruby. I was having the same problem that I solved by recompiling ruby from source.
Also, mysql gem 2.8 is (was?) incompatible with snow leopard, so you may try 2.7. There was an explanation of 2.8 issues somewhere on SO.

Installing MySQL and mysql gem on Snow Leopard

It´s really a hard job figuring out how to get MySQL and mysql gem up and running on Snow Leopard 10.6.2. I followed the instructions of various posts but was not successful yet:
I build MySQL Version 5.1.39 from source and it installed successfully. When trying to login using (mysql -u root -p) mysql returned the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
that obviously meant that the MySQL Server (mysqld) was not running.
which mysql: /usr/local/mysql/bin/mysql
which ruby: ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9])
gem -v: 1.3.5
mysql: Server version: 5.1.39 MySQL Community Server (GPL)
After a lot of googling around, I found out that
this command can start mysqld:
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
The Preference Pane MySQL Tool is probably broken in Mac OS X 10.5 and higher
This command should install the mysql gem correctly on Snow Leopard:
sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
It ended up that I got the following error using something like rake db:create:
dyld: lazy symbol binding failed: Symbol not found: _mysql_init
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_init
Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
Expected in: flat namespace
This error led me to the following post: http://cho.hapgoods.com/wordpress/?p=158, that basically tells me that the Ruby Version that came together with XCode 3.0 does not work in 64bit environments and a solution could be to install the 32bit versionof MySQL.
Any suggestions, how to proceed?
While building from source is not necessarily a bad idea, even if the official distribution is built using a better compiler, using MacPorts (http://www.macports.org/install.php) to do it is probably a better idea than a self-built installation.
Although you can wrangle the OS X supplied Ruby and MySQL into shape, in my experience it's easier to work entirely within the MacPorts realm (/opt) and leave your original distribution unmolested.
A further advantage is you get a more up-to-date Ruby executable. 10.6 ships with 1.8.7p72 where MacPorts provides 1.8.7p174, for instance.
Example:
sudo port install mysql5
sudo port install mysql5-server
sudo port install rb-mysql