04 Jun 2008, 05:30
David_pragsmall

David Schwartz (26 posts)

So, I’m just trying to figure out what I need to get my apps to interface with MySQL. I have a ‘mysql-2.7’ directory in /lib/ruby/gems/1.8/. Does that suggest that I have the adpaters in place already? (The instructions on http://www.tmtm.org/en/mysql/ruby/ leave MUCH to be desired).

TIA, David

04 Jun 2008, 08:21
Samr_small_pragsmall

Sam Ruby (584 posts)

If the following commands work, you should be good to go:

sudo gem update mysql
mysqladmin -u root create depot_development

The “Configure the Application” and “Testing Your Configuration” sections in chapter 6 may also be of help.

04 Jun 2008, 13:36
David_pragsmall

David Schwartz (26 posts)

The first command seems to have failed and the second command wasn’t found.

Updating installed gems… Bulk updating Gem source index for: http://gems.rubyforge.org Attempting remote update of mysql Building native extensions. This could take a while… ERROR: Error installing mysql: ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb update 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 ** extconf.rb failed ** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

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/local/bin/ruby –with-mysql-config –without-mysql-config –with-mysql-dir –without-mysql-dir –with-mysql-include –without-mysql-include=${mysql-dir}/include –with-mysql-lib –without-mysql-lib=${mysql-dir}/lib –with-mysqlclientlib –without-mysqlclientlib –with-mlib –without-mlib –with-mysqlclientlib –without-mysqlclientlib –with-zlib –without-zlib –with-mysqlclientlib –without-mysqlclientlib –with-socketlib –without-socketlib –with-mysqlclientlib –without-mysqlclientlib –with-nsllib –without-nsllib –with-mysqlclientlib –without-mysqlclientlib

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

04 Jun 2008, 15:08
Samr_small_pragsmall

Sam Ruby (584 posts)

bq. Check the mkmf.log file for more details.

That’s good advice. You look like you might be running on Linux? If so, this may help you find this file:

find /var/lib/gems/1.8/gems/ -name mkmf.log

Typical problems include not installing a prereq. On Ubuntu, you may need the following:

sudo apt-get install build-essential ruby1.8-dev libmysqlclient5-dev
04 Jun 2008, 17:15
David_pragsmall

David Schwartz (26 posts)

I’m running on OS X 10.5.3. I found one of two logs by that name in mysql-2.7. Here’s the first part of the log which appears to report an error:

=============== find_library: checking for mysql_query() in -lmysqlclient… ——————– no

“gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-darwin9.3.0 -I. -I/usr/local/include -D_XOPEN_SOURCE=1 -fno-common -pipe -fno-common conftest.c -L”.” -L”/usr/local/lib” -L”/usr/local/lib” -L. -lruby-static -lmysqlclient -lpthread -ldl -lobjc “ conftest.c: In function ‘t’: conftest.c:3: error: ‘mysql_query’ undeclared (first use in this function) conftest.c:3: error: (Each undeclared identifier is reported only once conftest.c:3: error: for each function it appears in.) checked program was: /* begin / 1: /top/ 2: int main() { return 0; } 3: int t() { void ((volatile p)()); p = (void (()()))mysql_query; return 0; } / end */ ===============

04 Jun 2008, 17:59
Samr_small_pragsmall

Sam Ruby (584 posts)

OK, so it doesn’t look like you have the mysqlclient library installed.

Two common ways to get mysql installed on OS X: “compiling it yourself”:http://hivelogic.com/articles/2007/11/installing-mysql-on-mac-os-x and “using ports”:http://codeintensity.blogspot.com/2007/09/installing-ruby-mysql-gem-with-macports.html

If you go the latter route, you will need to make sure that you first have “ports installed”:http://darwinports.com/install/

05 Jun 2008, 03:50
David_pragsmall

David Schwartz (26 posts)

So, I installed mysql with the help of the Hivelogic page. I tried to validate that the configuration is set (seemed to pass their test) with the ‘sudo gem update mysql’ you suggested but it seemed to fail. See the following:

Updating installed gems… Attempting remote update of mysql Building native extensions. This could take a while… ERROR: Error installing mysql: ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb update 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 /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection. Results logged to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out Gems updated: mysql

05 Jun 2008, 13:25
Samr_small_pragsmall

Sam Ruby (584 posts)

Once again, the log might be helpful, but I’ll take a guess that the gem installation couldn’t find the mysql libraries at all. Try following the “hivelogic instructions”:http://hivelogic.com/articles/2007/02/ruby-rails-mongrel-mysql-osx for installing mysql. You’ll note that they pass an additional parameter telling the gem installer where to find the mysql libraries.

05 Jun 2008, 15:41
David_pragsmall

David Schwartz (26 posts)

Should I remove what I’ve already done? FYI, my initial installation came per Hivelogic’s instructions. If so, what’s the best way of clearing everything out (Ruby, Rails, Mongrel, MySQL, Capistrano)?

Thanks for all your help!

David

05 Jun 2008, 15:52
Samr_small_pragsmall

Sam Ruby (584 posts)

No, I was just suggesting that you follow the mysql part of the instructions, specifically:

sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
06 Jun 2008, 19:40
David_pragsmall

David Schwartz (26 posts)

ho boy. I’ve now executed ‘sudo gem install mysql – –with-mysql-dir=/usr/local/mysql’ and get the same result upon executing ‘sudo gem update mysql’.

I don’t know where mysql is so don’t know where the log file is (I’m new to Unix as well :-( ). I have confirmed that mysql is installed though by getting into the mysql interpreter via ‘mysql -u root’.

Let me ask another dumb question. The following was part of the MySQL installation instructions from Hivelogic. I assumed that each line was a separate command. Is this correct?

CC=gcc CFLAGS=”-O3 -fno-omit-frame-pointer” CXX=gcc \ CXXFLAGS=”-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

Thanks for hanging in there with me!

David

09 Jun 2008, 23:01
David_pragsmall

David Schwartz (26 posts)

I hope you can stick with me! David

11 Jun 2008, 14:00
Samr_small_pragsmall

Sam Ruby (584 posts)

Sorry for the delay… I’m back now.

What you described above “CC=gcc … enabled-shared” actually is one command. If you dropped the trailing backslashes from all lines but the last one and concatenated it on one line, it should work the same. For convenience, Unix based command shells allow you to split up such commands into multiple lines by appending a backslash to the end of all but the last line.

But lets back up. There are several moving parts here. If you really want to stick with MySQL, you need several things. You need a MySQL server. You need a MySQL client. You need MySQL libraries. And you need a Ruby interface to those MySQL libraries.

The good news is that you might be there. If you can install the gem, you don’t need to update it. (In fact, as near as I can tell, both commands perform roughly the same function). You can tell for sure by issuing the following (filling in host, user and passwd):

irb
require 'mysql'
m = Mysql.new(host, user, passwd)
m.query('select version()').each {|row| puts row}

I’m a bit spoiled as I use sqlite3 and Ubuntu. Sqlite3 has many fewer moving parts. Even installing mysql-ruby on Ubuntu is as simple as apt-get install mysql-ruby.

12 Jun 2008, 02:37
David_pragsmall

David Schwartz (26 posts)

Sorry for being so dense but I presume that I make up the user and passwd. Where do I get the host?

David

12 Jun 2008, 08:48
Samr_small_pragsmall

Sam Ruby (584 posts)

You are going to need to start the server (see “instructions”:http://hivelogic.com/articles/2007/02/ruby-rails-mongrel-mysql-osx), and then specify the name of the host you started the server on. If you started the server on the same machine as the client, “localhost” will do. The default user is “root” and password is “”, but you probably want to “change”:http://dev.mysql.com/doc/refman/4.1/en/user-names.html that.

13 Jun 2008, 04:52
David_pragsmall

David Schwartz (26 posts)

Unfortunately, those instructions pointed to a page that no longer exists. I did find mysql-5.0.45-osx10.4-i686.dmg and downloaded it (but not installing just yet). I have mysql in /usr/local/ so I left it alone. (I’d like to install the new .dmg; how would I uninstall the mysql currently installed?)

This is what I got executing the commands you posted (the control panel shows that the server is running, btw):

david:~ david$ cd /usr/local/ david:local david$ irb irb(main):001:0> require ‘mysql’ LoadError: no such file to load – mysql from (irb):1:in `require’ from (irb):1 irb(main):002:0>

13 Jun 2008, 14:19
Samr_small_pragsmall

Sam Ruby (584 posts)

Before trying to install another version of MySQL, let’s see what you have got. I’m concerned about the confusion that trying to use the binding that you generated for one version of MySQL against another version of MySQL may cause.

Since the ‘require’ failed, you either don’t have the Ruby binding gem installed, or Ruby can’t find it. Let’s try two things.

First, lets verify that you have MySQL client and server installed:

mysql -u root
select version();
quit;

I’m following along on Ubuntu, and get 5.0.45-Debian_1ubuntu3.3-log.

Next, lets try adding an explicit require for rubygems:

irb
require 'rubygems'
require 'mysql'
m = Mysql.new(host, user, passwd)
m.query('select version()').each {|row| puts row}
13 Jun 2008, 23:48
David_pragsmall

David Schwartz (26 posts)

At this point, I think my mysql installation is seriously messed up. I can’t seem to start the server through my mysql preference panel. I get the following as well.

david:local david$ mysql -u root ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

Thanks again for sticking with me on this…..

15 Jun 2008, 14:38
Samr_small_pragsmall

Sam Ruby (584 posts)

Before assuming that you are messed up, are you sure that the server is started?

Also, just curious: you are aware that most of the topics covered in the book are database independent, right? Sqlite3 has fewer moving parts (in particular, no separate server). You should be able to proceed with sqlite3 in parallel while you are resolving this issue.

15 Jun 2008, 22:22
David_pragsmall

David Schwartz (26 posts)

right, I’ve been going through the book on my thinkpad (Win2K) but I do realize that I could also do the same on my Mac independent of this issue. Only once I start collaborating with my partner on our project will mysql become an issue.

As I said, the mysql preference panel indicates that the server isn’t running.

–d

16 Jun 2008, 12:19
Samr_small_pragsmall

Sam Ruby (584 posts)

What happens when you try to “start mysql”:http://developer.apple.com/internet/opensource/osdb.html?

sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
17 Jun 2008, 03:30
David_pragsmall

David Schwartz (26 posts)

It asks for a password.

22 Jun 2008, 16:47
David_pragsmall

David Schwartz (26 posts)

Still with me Sam?

24 Jun 2008, 10:56
Samr_small_pragsmall

Sam Ruby (584 posts)

On the systems I have installed it, mysql’s default user is root, and default password is blank, and generally are accompanied by instructions to change the password. Try it. But if you’ve changed the password, I don’t think I can be of much help with trying to recover it.

Previously I argued against reinstalling, based on not knowing what is going on, which made me concerned that reinstalling wouldn’t necessarily address the problem. But if the problem is a lost password, then re-installing may be an option.

I would recommend proceeding incrementally. Reinstall mysql if you must. Then proceed to starting the server. Only after you have been able to start the server, verify that you can access the server from the mysql client. Only after you have been able to verify access from the mysql client, try the simple ruby program I provided above. Only after the simple ruby program has been verified should you try configuring Rails to use mysql.

27 Jun 2008, 05:47
David_pragsmall

David Schwartz (26 posts)

So, I figured out how to uninstall mysql and deleted the package. I installed what I realized was the appropriate package for 10.5, updated the gems just fine and created depot_development database so I think I’m making progress.

When I went to install the adapters, I executed ‘ruby extconf.rb’ but it failed. Any thoughts?

Thanks, David


david:mysql-ruby-2.8pre2 david$ ruby extconf.rb 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 checking for main() in -lmygcc… no checking for mysql_query() in -lmysqlclient… no ** extconf.rb failed ** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.

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/local/bin/ruby –with-mysql-config –without-mysql-config –with-mysql-dir –without-mysql-dir –with-mysql-include –without-mysql-include=${mysql-dir}/include –with-mysql-lib –without-mysql-lib=${mysql-dir}/lib –with-mysqlclientlib –without-mysqlclientlib –with-mlib –without-mlib –with-mysqlclientlib –without-mysqlclientlib –with-zlib –without-zlib –with-mysqlclientlib –without-mysqlclientlib –with-socketlib –without-socketlib –with-mysqlclientlib –without-mysqlclientlib –with-nsllib –without-nsllib –with-mysqlclientlib –without-mysqlclientlib –with-mygcclib –without-mygcclib –with-mysqlclientlib –without-mysqlclientlib

27 Jun 2008, 08:09
Samr_small_pragsmall

Sam Ruby (584 posts)

Did you “check the mkmf.log”:http://forums.pragprog.com/forums/66/topics/500#posts-3052 ?

27 Jun 2008, 13:35
David_pragsmall

David Schwartz (26 posts)

Found the log in /Documents/RubyRails/mysql adapters/mysql-ruby-2.8pre2/. It contains lots of errors such as the following. Not sure what it all means.

David

find_library: checking for mysql_query() in -lmysqlclient… ——————– no

“gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-darwin9.3.0 -I. -I/usr/local/include -D_XOPEN_SOURCE=1 -fno-common -pipe -fno-common conftest.c -L”.” -L”/usr/local/lib” -L”/usr/local/lib” -L. -lz -lm -lruby-static -lmysqlclient -lz -lm -lpthread -ldl -lobjc “ conftest.c: In function ‘t’: conftest.c:3: error: ‘mysql_query’ undeclared (first use in this function) conftest.c:3: error: (Each undeclared identifier is reported only once conftest.c:3: error: for each function it appears in.) checked program was: /* begin / 1: /top/ 2: int main() { return 0; } 3: int t() { void ((volatile p)()); p = (void (()()))mysql_query; return 0; } / end */

“gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-darwin9.3.0 -I. -I/usr/local/include -D_XOPEN_SOURCE=1 -fno-common -pipe -fno-common conftest.c -L”.” -L”/usr/local/lib” -L”/usr/local/lib” -L. -lz -lm -lruby-static -lmysqlclient -lz -lm -lpthread -ldl -lobjc “ ld: library not found for -lmysqlclient collect2: ld returned 1 exit status checked program was: /* begin / 1: /top/ 2: int main() { return 0; } 3: int t() { mysql_query(); return 0; } / end */

“gcc -o conftest -I. -I/usr/local/lib/ruby/1.8/i686-darwin9.3.0 -I. -I/usr/local/include -D_XOPEN_SOURCE=1 -fno-common -pipe -fno-common conftest.c -L”.” -L”/usr/local/lib” -L”/usr/local/lib” -L. -lz -lm -lruby-static -lmysqlclient -lz -lm -lpthread -ldl -lobjc “ conftest.c: In function ‘t’: conftest.c:3: error: ‘mysql_query’ undeclared (first use in this function) conftest.c:3: error: (Each undeclared identifier is reported only once conftest.c:3: error: for each function it appears in.) checked program was: /* begin / 1: /top/ 2: int main() { return 0; } 3: int t() { void ((volatile p)()); p = (void (()()))mysql_query; return 0; } / end */

27 Jun 2008, 17:57
Samr_small_pragsmall

Sam Ruby (584 posts)

This is all “deja”:http://forums.pragprog.com/forums/66/topics/500#posts-3052 “vu”:http://forums.pragprog.com/forums/66/topics/500#posts-3056

I suggest that you take it slower. Here’s what I said before:

Then proceed to starting the server.

Were you able to do that?

Only after you have been able to start the server, verify that you can access the server from the mysql client.

Was this successful?

Only after you have been able to verify access from the mysql client, try the simple ruby program I provided above.

Did you try this?

Only after the simple ruby program has been verified should you try configuring Rails to use mysql.

. . .

  You must be logged in to comment