Learning Rails, issue 1
I'm reading "Agile development with Ruby on Rails".
That's the coolest technical book i've been reading recently.
I decided to document issues i have during reading, just stuff to remember :)
So the very first issue I had was error during script/genration running.
The issue looks like:
Errno::ENOENT: No such file or directory - /tmp/mysql.sock
Not so much helpful...Likely to be configuration issue.
Next time I run generator with --trace option again to see the stack and to try to find out the reason.
On the very top there's a ../mysql.rb:104, lets look at it:
if (host == nil or host == "localhost") and defined? UNIXSocket then
unix_socket = socket || ENV["MYSQL_UNIX_PORT"] || MYSQL_UNIX_ADDR
sock = UNIXSocket::new(unix_socket) # line 104
So it tries to use socket, then ENV["MYSQL_UNIX_PORT"], then MYSQL_UNIX_ADDR (which actually is a /tmp/mysql.sock if you look at the beginning of the mysql.rb). Here's our problem(you may want to dig deeper into the stack, to see that we really need socket: configuration entry)
But why it's using the default setting? Looks like unices are expected to connect via UNIXSocket rather than TCPSocket, and there's nothing in our connection profile about sockets, so lets add it to config/database.yml.
But how do i know this socket location? Well, on my FC6 it's pretty straightforward:
[gmarik:~/work/depot]$ netstat -an|grep mysql
unix 2 [ ACC ] STREAM LISTENING 36050 /var/lib/mysql/mysql.sock
unix 3 [ ] STREAM CONNECTED 413895 /var/lib/mysql/mysql.sock
to depot_development (or depot_test|depot_production) section.
After this tinkering we get back to business, developing our depot application:)