Mysql2 adapter unable to connect to MySQL

Hello,

When I am running the command “rails server”, I am getting the
following error
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/gems/
1.9.1/gems/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: undefined symbol:
RARRAY_LEN

Earlier, I got exactly the same error, when was I executing the
command
rake db:bootstrap
It got solved when I modified the command to the following
rake db:bootstrap --with-mysql-config=/usr/local/bin/mysql_config

I am understanding from the above that mysql2 adapter was not able to
find MySQL, which it was able to after passing the argument. Thinking
in those lines, I executed the following commands

rails server --with-mysql-config=/usr/local/bin/mysql_config
But, it does not solve it rails does not take that argument

I then put the parameter
–with-mysql-config=/usr/local/bin/mysql_config
in a configuration file and executed
rails server --config=configFileMysql

I am getting the following message
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/
active_support/dependencies.rb:239:in `require’: no such file to load
– ./configFileMysql (LoadError)

I also want to mention that I am running “rails server” command to run
spreecommerce 0.40.3 package.

Could anyone please help me as to how to solve the error I pointed out
earlier regarding RARRAY_LEN

I have the following content in my database.yml

development:
adapter: mysql2
encoding: utf8
reconnect: false
database: fourth_development
pool: 5
username: root
password:
socket: /var/lib/mysql/mysql.sock

I also want to mention that mysql client did not work earlier and it
was giving following error
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
‘/tmp/mysql.sock’ (2)
I had to change the command from
“mysql” to
mysql --user=root --password --socket=/var/lib/mysql/mysql.sock
in order to make it work
and also add
in my /etc/my.cnf file, I had to change it to
[client]
socket: /var/lib/mysql/mysql.sock

On my Fedora 14 OS, I have the following installed
Rails 3.0.5, installed at
/usr/local/bin/rails

ruby --version
gives me
ruby 1.9.2p0 (2010-08-18) [i686-linux]
whereis ruby
gives me
ruby: /usr/lib/ruby /usr/local/bin/ruby /usr/local/lib/ruby

mysql Ver 14.14 Distrib 5.1.51, for pc-linux-gnu (i686) using
EditLine wrapper

/etc/rc.d/init.d/mysql status
MySQL running (28105) [ OK ]

Thanks a bunch,
Ajay

On Sat, Mar 12, 2011 at 8:11 AM, Ajay [email protected] wrote:

rake db:bootstrap
I then put the parameter
spreecommerce 0.40.3 package.
database: fourth_development
“mysql” to

/etc/rc.d/init.d/mysql status
MySQL running (28105) [ OK ]

Hi Ajay,

Have you tried uninstalling mysql2 gem and reinstalling it with the
following command?

gem install mysql2 – --with-mysql-config=/usr/local/bin/mysql_config

B.

Hi Bryan,

I executed the following command
gem uninstall mysql2

followed by the command you mentioned.

I then executed the command
rails server
But, I am getting the same error. Please let me know, if you have any
other ideas that I can try.

Thanks,
Ajay

On Mar 12, 9:11am, Ajay [email protected] wrote:

Hello,

When I am running the command “rails server”, I am getting the

i have same problem on windows xp
i tried many ways, even i could excute rails server but after running
server, rails application doesn’t work

On Sun, Mar 13, 2011 at 3:45 AM, Alir3z4 [email protected] wrote:

The issues that are happening here are on Ubuntu and not Windows. Please
post what error are you getting when you run rails server?

Thanks,
B.

On Sat, Mar 12, 2011 at 11:52 PM, Ajay [email protected] wrote:

other ideas that I can try.

Hi Ajay,

It might still be that it doesn’t understand how to talk to MySQL. I’m
just
trying to cover the it knowing where things are. It may still not know
which
socket to use. I ran into this issue on a Linux machine once and got
around
it by symlinking from the tmp folder to the actual socket. Try that and
see
what happens.

cd /tmp
sudo ln -s /var/lib/mysql/mysql.sock mysql.sock

Thanks,
B.

On 14 Mar 2011, at 18:39, Ajay [email protected] wrote:

Hi Bryan,

I executed the symlink command you sent me and then executed
rails server
But, I am still getting the same error.
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/gems/
1.9.1/gems/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: undefined symbol:
RARRAY_LEN

In addition, I have done the following experiments

I think you are getting confused as you have several things going wrong
at the same time.

  • something owned by root that is stopping webrick from dripping its pid
    file. Fix this by fixing the permissions on the folder it’s trying to
    write its pid file to, not by running as root.
  • something wrong with your mysql gem (the messages about RARRAY_LEN)
  • possibly something wrong with your mysql install (if the only mysql
    problem you have is the RARRAY_LEN message then i’d stop fiddling with
    my.cnf - it’s extremely unlikely that a problem with your mysql install
    caused that

Other things: don’t run bundle:install as root - that will screw things
up. If you have multiple versions of ruby installed, make sure
rake,rails etc. are the ones from the ruby version you actually want (if
my memory is correct RARRAY_LEN was a #define macro pre ruby 1.9, but
became an actual function in 1.9, trying to load something compiled for
1.9 with the wrong ruby might cause that message (although gems should
be segregated by ruby version))

Fred

Hi Bryan,

I executed the symlink command you sent me and then executed
rails server
But, I am still getting the same error.
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/gems/
1.9.1/gems/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: undefined symbol:
RARRAY_LEN

In addition, I have done the following experiments
rails new blog -d=mysql
cd blog
su bundle install
rake db:create
rails server

The above set of instructions are rails instructions for getting
started on rails. With these instructions, rails server starts well at
the following URL
http://0.0.0.0:3000

For the above set of instructions, I have the following lines in my
GemFile

gem ‘rails’, ‘3.0.5’
gem ‘mysql2’

In my config/database.yml, I have
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: blog_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock

I tried having
socket: /var/lib/mysql/mysql.lock
with the symbol link and without it. It does not seem to make any
difference.

With the spree package that I am trying to run, I have the following
content in my Gemfile

gem ‘rails’, ‘3.0.5’

Bundle edge Rails instead:

gem ‘rails’, :git => ‘git://github.com/rails/rails.git’

gem ‘mysql2’
gem ‘newrelic_rpm’

Followed by spree itself first, all spree-specific extensions second

gem ‘spree’, ‘0.40.3’
gem ‘spree_active_shipping’, :git => ‘https://github.com/spree/
spree_active_shipping.git’
gem ‘spree_product_assembly’, :git => ‘git://github.com/spree/spree-
product-assembly.git’
gem ‘spree_static_content’, :git => ‘git://github.com/spree/
spree_static_content.git’

I executed the following set of commands
rails new xyz -d=mysql
cd xyz
su bundle install
rake db:create

rails g spree:site
rake spree:install

rake spree_sample:install
rails server --config=/usr/local/bin/mysql_config

Above are the instructions given for spree at the URL,
http://spreecommerce.com/documentation/getting_started.html

config/database.yml is same as previously mentioned

Now executing,
rails server
gives
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/gems/
1.9.1/gems/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: undefined symbol:
RARRAY_LEN

Question is my why two different results? Is it because in one of the
case, mysql connection is not needed as no information is there in the
tables?

Also, I had tried downgrading rails to 3.0.4 and then executing the
above set of instructions. But, same error

I read in the following post
http://www.linuxforums.org/forum/red-hat-fedora-linux/31155-error-2002-hy000-cant-connect-local-mysql-server.html
that adding host name resolves the issue
Therefore, I tried different options like
host = starwars.localdomain
host = starwars
in /etc/my.cnf

But, when I do that I am unable to restart my MySQL server as it says
that PID file has not been written to (or unable to write).
Therefore, I am unable to mention
host=0.0.0.0, which where rails server is getting started

I get similar error of unable to start mysql server, when I have
socket=/tmp/mysql.sock
in /etc/my.cnf

Thinking that linking was not allowed, I even tried disabling the
following line in /etc/my.cnf
symbolic-links=0
But, again server does not start, whenever I change anything in /etc/
my.cnf

My present my.cnf content is as follows
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#socket=/tmp/mysql.sock
user=mysql

Disabling symbolic-links is recommended to prevent assorted security

risks
symbolic-links=0
#host=starwars

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
socket=/var/lib/mysql/mysql.sock
#socket=/tmp/mysql.sock
#host=starwars.localdomain

In one situation, which I can still reproduce, I am getting the
following error, when I running as non-root

=> Booting WEBrick
=> Rails 3.0.4 application starting in development on
http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/local/lib/ruby/gems/1.9.1/gems/gems/rack-1.2.2/lib/rack/server.rb:
267:in initialize': Permission denied - /home/Ajay/spree/rails4store/ tmp/pids/server.pid (Errno::EACCES) from /usr/local/lib/ruby/gems/1.9.1/gems/gems/rack-1.2.2/lib/rack/ server.rb:267:inopen’
from /usr/local/lib/ruby/gems/1.9.1/gems/gems/rack-1.2.2/lib/rack/
server.rb:267:in write_pid' from /usr/local/lib/ruby/gems/1.9.1/gems/gems/rack-1.2.2/lib/rack/ server.rb:203:instart’
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.4/lib/rails/
commands/server.rb:65:in start' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.4/lib/rails/ commands.rb:30:inblock in <top (required)>’
from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.4/lib/rails/
commands.rb:27:in tap' from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.4/lib/rails/ commands.rb:27:in<top (required)>’
from script/rails:6:in require' from script/rails:6:in

Thinking that probably I need to run as root, I executed as root
It then gives the usual mysql2 error that I mentioned earlier. I
thought of mentioning it to you in case you have seen this error
before.

Please let me know if I am missing something or any other ideas that
you have, which I can try out.

Thanks a lot for your help,
Ajay

Hi Fred,

Thanks for your comments and suggestions. They were really useful.

I first noticed that I had two mysql installations in my system - one
through compilation and another installed through yum.
I uninstalled both and had only one. But, it did not result in any
change in error.

I then thought of focusing my attention on ruby.
My system had ruby-1.9.2-p0 and it was installed by compiling it from
source.
Therefore, I thought of installing through yum. But, ruby 1.8.7 was
only available through rpm

I have now installed ruby-1.9.2 through rvm. Some other errors
occured, sort of irrelevant to the topic. After solving those
problems, I finally executed the command
rails server
The error with mention of RARRAY_LEN did not occur .

In short, I was able to successfully start the rails server.

Thanks a lot for your help,
Ajay