Topic: No such file or directory - /tmp/mysql.sock

Ok, I installed rails on a new Fedora Core 5 yesterday.
I created an app, I loaded some MySQL tables, All Ok.

Today I enter:
$ ruby script/generate scaffold Product Admin
and it gives me the message: No such file or directory - /tmp/mysql.sock

Also I look in /config/database.yml and it says install mysqldriver using:
[root@localhost depot]# gem install mysql
which fails giving:
    ERROR:  While executing gem ... (RuntimeError)
    ERROR: Failed to build gem native extension.

mysql  Ver 14.12 Distrib 5.0.22
Server version:         5.0.22
Protocol version:       10

How do I tell rails about MySQL?

Re: No such file or directory - /tmp/mysql.sock

Is MySQL currently running? Perhaps you restarted and MySQL isn't set to launch automatically on start up. You can try running the "mysql" command and see if you get the "Welcome to the MySQL monitor..." message or the "No such file or directory - /tmp/mysql.sock" message.

Railscasts - Free Ruby on Rails Screencasts

Re: No such file or directory - /tmp/mysql.sock

Yup, it's running fine, I can see the tbles from the client and
it shows up in KDE's services browser as a running process

Re: No such file or directory - /tmp/mysql.sock

As far as I know, in Fedora Core the mysql.sock file isn't located in the tmp dir. It should be somewhere in /usr/lib/ or so, but I'm not shure. You can check the config mysql config file in /etc.
EDIT: The sock file should be located here:
/var/lib/mysql/mysql.sock

Alternatively you can use set the following in your database.yml:
host: 127.0.0.1
port: 3306

and delete the sock line.
Then rails should connect to the database server thought tcp instead of a socket.

Last edited by Dieter Komendera (2006-09-27 19:20:04)

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: No such file or directory - /tmp/mysql.sock

Yup its finding MySql now... but...
Lost connection to MySQL server during query

Thanks -- I'll investigate further.

Last edited by giveitago (2006-09-27 19:36:27)

Re: No such file or directory - /tmp/mysql.sock

Do you have the mysql-ruby bindings installed?
Or are you still trying to install them?

Last edited by Dieter Komendera (2006-09-28 02:31:25)

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: No such file or directory - /tmp/mysql.sock

Nope, I still got the same result if I run
[root@localhost]# gem install mysql

So I found a file my.cnf in /etc with mysql config details:
[root@localhost]# gem install mysql -- --with-mysql-config=/etc/my.cnf
or
{root@localhost]# ruby extconf.rb  --with-mysql-config=/etc/my.cnf
both produce the error:
extconf.rb:1: command not found: /etc/my.cnf --cflags
*** extconf.rb failed ***

my.cnf contains:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
     
[mysql.server]
user=mysql
basedir=/var/lib

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

Thats the unchanged Fedora file - do I need to add anything to it?

Re: No such file or directory - /tmp/mysql.sock

As far as I remember, I didn't changed anything in the mysql config file. Whats the exact output when yor run
gem install mysql

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: No such file or directory - /tmp/mysql.sock

I've had luck with the following database.yml file when switching between various Linux distributions.  Maybe it could help you track down this issue.

login: &login
  adapter:  mysql
  username: user
  password:
  socket:  <%=
    ['/opt/local/var/run/mysql5/mysqld.sock', # darwinports
     '/opt/local/var/run/mysqld/mysqld.sock', # darwinports, again
     '/var/run/mysqld/mysqld.sock',           # ubuntu/debian
     '/tmp/mysql.sock'].select { |f| File.exist? f }.first %>

development:
  <<: *login
  database: rails_development

test:
  <<: *login
  database: rails_test

production:
  <<: *login
  database: rails

Re: No such file or directory - /tmp/mysql.sock

OK putting the correct socket path in database.yml worked
I now have a scaffold script that works - many thanks

I still didn't get to intall the native extension but I'm back on the rails anyhow.

This is the output from gem install mysql:

[root@localhost rod]# gem install mysql -- --with-mysql-config=/etc/my.cnf
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.1 (mswin32)
2. mysql 2.7 (ruby)
3. mysql 2.6 (ruby)
4. mysql 2.5.1 (ruby)
5. Cancel installation
> 2
Building native extensions.  This could take a while...
extconf.rb:1: command not found: /etc/my.cnf --cflags
*** 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/bin/ruby
        --with-mysql-config

ERROR:  While executing gem ... (RuntimeError)
    ERROR: Failed to build gem native extension.
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
[root@localhost rod]# cat /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

[root@localhost rod]# cat /usr/lib/ruby/gems/1.8/gems/mysql-2.7/mkmf.log
cat: /usr/lib/ruby/gems/1.8/gems/mysql-2.7/mkmf.log: No such file or directory
[root@localhost rod]#

Last edited by giveitago (2006-09-28 10:11:05)

Re: No such file or directory - /tmp/mysql.sock

Do you have the mysql-dev rpm installed?

My homepage: http://www.komendera.com/
Working at: http://www.abloom.at/
My blog: soaked and soaped http://soakedandsoaped.com/

Re: No such file or directory - /tmp/mysql.sock

For a quick fix have you tried making a symbolic link from /tmp/mysql.sock to where your mysql.sock file really is?

Last edited by Jonathan (2006-10-06 05:51:10)