Error: uninitialized constant MysqlCompat::MysqlRes

For all you folks who couldn’t get this to work on Snow Leopard inspite
of trying the ridiculously simple solution(s) mentioned above,

Try this:
Re compile ruby. Then do

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

This will ensure that the right arch of ruby is used to compile the
native extensions.

Pishty Ags wrote:

Evan G. wrote:

This didn’t seem to fix the error for me. I still get ‘uninitialized
constant MysqlCompat::MysqlRes’

Kyle F. wrote:

To fix this, specify ARCHFLAGS when you install the ‘mysql’ gem:

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

On Aug 27, 12:07�pm, Caleb C. [email protected]

cheers,

on my Centos Machine, i had to install mysql-devel.x86_64 first, then i
ran the command:

env ARCHFLAGS=“-arch x86_64” gem install mysql –
–with-mysql-config=/usr/lib64/mysql/mysql_config

which did the trick.

thanks Kyle

I use Centos , but it’s i386 . So I installd mysql-devel,and use the
command:
env ARCHFLAGS=“-arch i386” gem install mysql –
–with-mysql-config=/usr/lib/msyql/mysql_config",
and it did the work , Aha!

Nikhil Gupte wrote:

For all you folks who couldn’t get this to work on Snow Leopard inspite
of trying the ridiculously simple solution(s) mentioned above,

Try this:
Re compile ruby. Then do

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

This will ensure that the right arch of ruby is used to compile the
native extensions.

and how do you recompile Ruby…

New to the OSX platform…

Thanks.

I went through this within the last two days. Might be useful to see
my write up here, too:

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/37b593be608e2461/1ace7ea9d30ef28a#1ace7ea9d30ef28a

Jean,

Best is to install macports, if you aren’t already using it.

To re-compile ruby, run:

sudo port install ruby

Nikhil Gupte wrote:

Jean,

Best is to install macports, if you aren’t already using it.

To re-compile ruby, run:

sudo port install ruby

I was able to get mysql gem to install on OSX Leopard without warnings
with the --no-rdoc and --no-ri switches; archflags likewise eliminated
the uninitialized constant error:

sudo gem install mysql --no-rdoc --no-ri –
–with-mysql-config=/usr/local/mysql/bin/mysql_config

That hasn’t made my installation functional however. I just rebuilt my
entire project with rails myApp -d mysql; I then scaffolded 5 sets of
tables (i.e. script/generate scaffold tablename c_code:string
c_name:string tran_id:integer priority:integer); I next drag the project
directory onto XCode Organizer; create the start server script
(script/server); and start the gem server in terminal: gem server.

Fine and dandy so far (seemingly). Then I run rake db:migrate to
engender the following error:

iMacMike:pfmpe mikemontagne$ rake db:migrate --trace
(in /Users/mikemontagne/rproj/pfmpe)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Unknown database ‘pfmpe_development’


database.yml indicates that this is supposed to be the development
database. But no such file exists in my project directory.

Is this a MySQL server configuration issue? Does anybody understand why
this table is not being created?

On Sun, Mar 21, 2010 at 5:45 PM, Mike M. [email protected]
wrote:

iMacMike:pfmpe mikemontagne$ rake db:migrate --trace

Unknown database ‘pfmpe_development’

database.yml indicates that this is supposed to be the development
database. But no such file exists in my project directory.

What file would you expect? This refers to a database, physical
location dependent on your MySQL configuration.

Is this a MySQL server configuration issue? Does anybody understand why
this table is not being created?

Perhaps you left out the step where you create it? At least I didn’t see
it in your post. You can create databases manually through the MySQL
CLI console or a number of other tools, or you can run the appropriate
rake task. rake -T will give you a list of the available tasks.

But you do have to create it before running your migrations :slight_smile:

HTH,

Hassan S. ------------------------ [email protected]
twitter: @hassan

I am not sure of why this error is coming, but just for a moment, try
rake
db:create before doing rake db:migrate.
It might solve your problem.

I had this issue after upgrading from ubuntu 9.10 (karmic) to 10.4
(lucid).
the solution was to libmysqlclient16-dev:

sudo aptitude install libmysqlclient16-dev

Using Mac OS X 10.6.4, the solutions above didn’t work for me. I
removed the gem, then tried:
gem install ruby-mysql

instead of the various attempts to get “gem install mysql” to work.

At a glance, this appears to have worked, and my ruby on rails is able
to access database.

Thanks Na Na, I was able to fix the issue by uninstalling the mysql gem
and then installing ruby-mysql gem.

Na Na wrote:

Using Mac OS X 10.6.4, the solutions above didn’t work for me. I
removed the gem, then tried:
gem install ruby-mysql

instead of the various attempts to get “gem install mysql” to work.

At a glance, this appears to have worked, and my ruby on rails is able
to access database.

Leopard 10.6.4.
Solved on my side by reinstalling mysql, using the 64bits version
instead of the mistakenly installed 32bits. Obvious ?

Jatin kumar wrote:

I am not sure of why this error is coming, but just for a moment, try
rake
db:create before doing rake db:migrate.
It might solve your problem.

The Mysql::Result constant is defined in the mysql_api gem (.so shared
object) - this is located in
gems/1.9.1/gems/mysql-2.8.1/ext/mysql_api/mysql_api.so

To fix the error the cleanest way I could think of - I created a
symbolic link to this object in /usr/lib/ruby/1.9.1/ - which is in
Ruby’s $LOAD_PATH variable - which you can see your own version via :
irb; puts “#{$LOAD_PATH}”;

  • None of the solutions people had posted on the web helped me - the
    main ones I kept seeing were - reinstall the mysql gem with ARCH_FLAGS
    set differently - and make a symbolic link mysql -> ‘.’ because Ruby was
    looking one directory too deep

I’m using Ubuntu Karamic Koala, Ruby 1.9.1, mysql-2.8.1, rails-2.3.5

Kyle F. wrote:

To fix this, specify ARCHFLAGS when you install the ‘mysql’ gem:

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

On Aug 27, 12:07�pm, Caleb C. [email protected]

Exactly the answer I needed. Thanks!

Kyle F. wrote:

To fix this, specify ARCHFLAGS when you install the ‘mysql’ gem:

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

On Aug 27, 12:07�pm, Caleb C. [email protected]

This fixed the problem for me. thanks!

-Jason

Thanks Kyle, worked awesomely on my macosx machine.

Kyle F. wrote in post #846791:

To fix this, specify ARCHFLAGS when you install the ‘mysql’ gem:

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

On Aug 27, 12:07 pm, Caleb C. [email protected]

Oren G. wrote in post #923611:

I had this issue after upgrading from ubuntu 9.10 (karmic) to 10.4
(lucid).
the solution was to libmysqlclient16-dev:

sudo aptitude install libmysqlclient16-dev

As a Ubuntu user that did the trick for me.
Thanks a lot, Oren! Your decision to post this probably saved hours of
work for me.

Raphael Petegrosso wrote in post #859937:

I was having the same problem on Snow Leopard and, after some time I
did the following:

Removed all mysql gems I had:

gem uninstall mysql

In my case I had to specify both mysql-dir and mysql-config (and -arch
x86_64 to 64 bits)

export ARCHFLAGS="-arch i386 -arch x86_64" ; gem install --no-rdoc –
no-ri mysql – --with-mysql-dir=/usr/local --with-mysql-config=/usr/
local/mysql/bin/mysql_config

Hope it works

I tried this and got the following message (also using Snow Leopard)

ERROR: While executing gem … (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)

Michael S. wrote in post #980959:

Raphael Petegrosso wrote in post #859937:

I tried this and got the following message (also using Snow Leopard)

ERROR: While executing gem … (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)

do :

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

Hi,

After all attempts. I simply uninstall mysql 5.5.9 (64 bits) and all
mysql gems.

Then install Mysql 5.1.55 (64 bits) and

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

and it works on MAC…

Hope it helps.

Matthew Werner wrote in post #982105:

Hi All,

This has been the most thorough discussion of the topic I’ve found. I’ve
spent far too much time trying to get this stupid gem to work. I’m going
to post the information i’ve got and I’m praying someone out there will
be able to help me.

ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
mysql --version
mysql Ver 14.14 Distrib 5.5.9, for osx10.6 (i386) using readline 5.1
rails -v
Rails 2.3.5
sudo gem uninstall mysql
Successfully uninstalled mysql-2.8.1

Here is where I’ve seen so so (SO) many different recommendations on
what to do. I’ve tried damn near everything, both sudo and not,
specifying my arch flags and not. I’ll just go with the most thorough:

export ARCHFLAGS="-arch i386" ; sudo gem install --no-rdoc --no-ri mysql –
–with-mysql-dir=/usr/local
–with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while…
Successfully installed mysql-2.8.1
1 gem installed

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
=> Environment: Development
** Execute db:migrate
rake aborted!
uninitialized constant MysqlCompat::MysqlRes

/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:440:in

`load_missing_constant’

/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in

`const_missing’

/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/mysql_adapter.rb:9:in

`define_all_hashes_method!’

I’m lost on what else it could be. I feel like I’ve tried every
combination. I’ve tried reinstalling ruby, 64bit of mysql, please help.
I’m out of ideas.