Topic: (sorry) Rails and MySQL not getting it on

I appreciate that this is one of the more common installation pitfalls but I'm stumped!

This is my third install of Rails (each time having used a different method!) and I'm using MacPorts to setup a Rails and MySQL environment on my Apple MacBook Pro (10.4.10).

I'm following Agile Web Development With Rails (2nd Edition) and have just attempted to use the depot_development MySQL database required for the web application.

Firstly, all of the MacPorts packages installed fine (following Duncan Davidson's method as instructed by the book). I am using the root username and have created a password for this account (which I have updated database.yml to reflect).

Here is the error (I gather from other sources this is ambiguous - and I have looked in MANY other sources!):

Chimera:~/Sites/depot Lloyd$ rake db:migrate
(in /Users/Lloyd/Sites/depot)
rake aborted!
Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)

(See full trace by running task with --trace)


To be honest I don't know what the problem could be or how to fix it!

Many thanks in advance,


Lloyd

Re: (sorry) Rails and MySQL not getting it on

I don't connect through the socket directly preferring to connect to the hostname using the mysql gem.

(sudo) gem install mysql

Then just use host: in your database.yml
development:
  host: localhost
  username: ...
  password: ...
  database: ...

I don't know anything about mysql on a mac so I don't know where the socket would be located although Rails should give a file which exists when you run 'rails project_name'.

The actual rails source gives these three paths for macs, perhaps you could try them?

"/opt/local/var/run/mysqld/mysqld.sock",  # mac + darwinports + mysql
"/opt/local/var/run/mysql4/mysqld.sock",  # mac + darwinports + mysql4
"/opt/local/var/run/mysql5/mysqld.sock",  # mac + darwinports + mysql5

Last edited by shadow (2007-08-14 13:44:59)

Re: (sorry) Rails and MySQL not getting it on

Hi Adam,

Like yours, my database.yml host is localhost.

So do I need to uninstall the MacPorts packages:

mysql5 +server, rb-mysql and rb-termios using

$ sudo port uninstall x

(where x is the package name)

...then 

sudo gem install mysql

???

Thanks.

Re: (sorry) Rails and MySQL not getting it on

Don't uninstall anything, just run "gem install mysql" and remove the socket: line from your database.yml and see what happens...

Last edited by shadow (2007-08-14 14:00:41)

Re: (sorry) Rails and MySQL not getting it on

hmmm, well that's not good!

Chimera:~ Lloyd$ sudo gem install mysql
Select which gem to install for your platform (i686-darwin8.10.1)
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
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=/opt/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 /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out


btw. I had localhost in my database.yml all along.

Thanks.

Re: (sorry) Rails and MySQL not getting it on

Looks like gem can't find your mysql installation - are you sure its installed correctly?

A host connection will only work if the mysql gem is installed, if it doesn't it will revert to using a socket connection.

I tend to compile and install all these things myself rather than using these "fancy" pre-made rails installers which seem to cause more problems than they're worth quite a bit of the time.

Last edited by shadow (2007-08-14 14:31:43)

Re: (sorry) Rails and MySQL not getting it on

I'm coming around to agreeing with you. The first install I did was totally manual and while it required a little more attention during install, it was, as you say, less problematic.

Do you know a way I can rid my system of the broken install I currently have so that I can start over and compile everything manually?

Re: (sorry) Rails and MySQL not getting it on

Sorry, I don't - I'm not a mac user* and I have no idea what software you are using.

Would http://appzapper.com/ help? I've only heard of it in passing.

* although the new imacs and textmate are making it hard not to be become one.

Last edited by shadow (2007-08-14 14:43:16)

Re: (sorry) Rails and MySQL not getting it on

AppZapper's more like 'Remove Programs' in Windows but thanks for the suggestion.

Textmate (and new kid on the block Coda for that matter) make OS X the only web dev platform I'd consider (I'm experienced on the web design side of things, just not the backend bit).

More people are switching everyday, there must be something to it!

Thanks again for the help, with a little luck I'll have a nice clean working install by tonight!


Lloyd

Re: (sorry) Rails and MySQL not getting it on

Yeh, clean install is the way to go:

* mysql - http://dev.mysql.com/downloads/mysql/5.0.html
* ruby - http://www.ruby-lang.org/en/downloads/
* rubygems - http://rubyforge.org/frs/?group_id=126
* gem install rails --include-dependencies
* gem install mysql mongrel_cluster