PDA

View Full Version : Ruby and MySQL Problem: Access Denied; Works fine manually



Phoenix Rising
18th February 2008, 06:01 PM
Howdy fellas -

I've recently installed FC8 on a VPS from Slicehost, and I'm having some problems getting Ruby to work properly with MySQL. This has got to be the strangest thing I've ever encountered.

When executing the following:
rake RAILS_ENV=production db:migrate

MySQL denies access to the user listed in my database.yml file. Now here's the funny thing: If I manually type out on the console:

mysql -u <myuser> --host=<myhost> -p
<plug in password>

I'm let in perfectly fine every time.

I further debugged by launching irb:

[me@mybox current]$ irb
irb(main):001:0> require 'mysql'
=> true
irb(main):002:0> dbh = Mysql.real_connect("localhost", "testuser", "testpass", "db")
=> #<Mysql:0x2b34817f6080>
irb(main):004:0> dbh.get_server_info
=> "5.0.45"
irb(main):005:0>

So we know that Ruby can in fact connect to MySQL when I do it personally, but for some reason, rake won't.

I've also tried using a completely different host as well. While of course I can plug in the hostname (actually an IP) on the console as well as all the other credentials and connect fine, even when I have database.yml updated correctly, it gives me the exact same error (with username changed of course).

Does anyone have any ideas why this could be happening or what I'm doing wrong?

Phoenix Rising
18th February 2008, 09:31 PM
Update

Still not working, but moving forward. Here's my most recent issue:


[root@mybox ~]# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
Need to update 9 gems from http://gems.rubyforge.org
.........
complete
Select which gem to install for your platform (x86_64-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation
> 3
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb install mysql -- --with-mysql-config=/usr/bin/mysql_config
checking for mysql_ssl_set()... no
checking for mysql.h... yes
creating Makefile

make
gcc -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_H -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -fPIC -c mysql.c
mysql.c: In function 'make_field_obj':
mysql.c:185: warning: unused variable 'hash'
mysql.c: In function 'stmt_execute':
mysql.c:1316: warning: unused variable 'false'
mysql.c: In function 'time_inspect':
mysql.c:1714: warning: format '%04d' expects type 'int', but argument 3 has type 'long int'
mysql.c:1714: warning: format '%02d' expects type 'int', but argument 4 has type 'long int'
mysql.c:1714: warning: format '%02d' expects type 'int', but argument 5 has type 'long int'
mysql.c:1714: warning: format '%02d' expects type 'int', but argument 6 has type 'long int'
mysql.c:1714: warning: format '%02d' expects type 'int', but argument 7 has type 'long int'
mysql.c:1714: warning: format '%02d' expects type 'int', but argument 8 has type 'long int'
mysql.c: In function 'time_to_s':
mysql.c:1727: warning: format '%04d' expects type 'int', but argument 3 has type 'long int'
mysql.c:1727: warning: format '%02d' expects type 'int', but argument 4 has type 'long int'
mysql.c:1727: warning: format '%02d' expects type 'int', but argument 5 has type 'long int'
mysql.c:1727: warning: format '%02d' expects type 'int', but argument 6 has type 'long int'
mysql.c:1727: warning: format '%02d' expects type 'int', but argument 7 has type 'long int'
mysql.c:1727: warning: format '%02d' expects type 'int', but argument 8 has type 'long int'
mysql.c: In function 'time_initialize':
mysql.c:1703: warning: control reaches end of non-void function
mysql.c: In function 'stmt_execute':
mysql.c:1365: warning: 't.time_type' is used uninitialized in this function
mysql.c:1378: warning: 't.time_type' is used uninitialized in this function
gcc -shared -o mysql.so mysql.o -L"." -L"/usr/lib64" -L. -rdynamic -Wl,-export-dynamic -lruby -L/usr/lib64/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto -lpthread -ldl -lcrypt -lm -lc
/usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz
/usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for -lz
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [mysql.so] Error 1


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

So I can't seem to figure out why gem won't compile the MySQL library. Any thoughts?