Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL hell... can't connect to database /tmp/mysql.sock

Update: I've STOPPED the older mysql process which was running and causing some confusion. Now I think I have only the newer (5.1.40) version running. BUT, it's pointing to the wrong data file. It's pointing to a default install data file and I'd like it to point to the existing data file in /var/mysql. Here's a portion of /etc/my.cnf

# The following options will be passed to all MySQL clients
[client]
#password   = your_password
port        = 3306
socket      = /var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port        = 3306
socket      = /var/mysql/mysql.sock

this is pointing to the older mysql.sock. I can't seem to find in the directory tree of the newer MySQL install?!? unless it's somewhere obscure.

Anyone help? Basically I installed a newer MySQL and now need to get this new version to launch with my existing data. And sort out this mysql.sock thing....


I've recently updated MySQL on Mac OS X Server and am having a hell of a time connecting to it from a rails app. or consistently from the command-line for that matter.

i'm sure this is an obvious error on my part but I only have moderate command-line experience so hoping someone can help...

also related is my rails app no longer can connect. Failing to connect via /tmp/mysql.sock but I'm not sure why it's looking there because there is no mysql.sock in /tmp and I don't know what/where it should be....

Edit: adding results from mysql_config --sockets

$ mysql_config --sockets
Usage: /usr/local/mysql/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/local/mysql/include  -g -Os -arch ppc -fno-common   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL]
        --include        [-I/usr/local/mysql/include]
        --libs           [-arch ppc  -L/usr/local/mysql/lib -lmysqlclient -lz -lm     -lmygcc]
        --libs_r         [-arch ppc  -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm     -lmygcc]
        --plugindir      [/usr/local/mysql/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [5.1.40]
        --libmysqld-libs [-arch ppc  -L/usr/local/mysql/lib -lmysqld -ldl  -lz -lm       -lmygcc]

Edit2 which mysql_config

$ which mysql_config
/usr/local/mysql/bin/mysql_config
like image 671
Meltemi Avatar asked Nov 22 '10 22:11

Meltemi


People also ask

What is sock file in mysql?

MySQL manages connections to the database server through the use of a socket file, a special kind of file that facilitates communications between different processes. The MySQL server's socket file is named mysqld. sock and on Ubuntu systems it's usually stored in the /var/run/mysqld/ directory.

Why mysql sock is missing?

mysqld. sock is created by the mysql daemon on start, and it is removed (or, becomes un-connectable) if this daemon stops. This message is given by some client process, trying to connect your mysqld on this socket without success. Its most likely reason is that the mysqld doesn't run.


2 Answers

You are trying to use different sockets for the server and client. Your Rails is trying to connect to /tmp/mysql.sock, by MySQL is listening on /var/mysql/mysql.sock.

Normally MySQL configuration is stored in /etc/my.cnf, but in your ps your output I see socket path is given as a parameter. So really depends on your system's specifics.

Anyway, look in /etc/my.cnf and your database.yml and make sure mysql.sock appears at the same path in both files.

like image 78
cababunga Avatar answered Sep 19 '22 15:09

cababunga


Not sure whether this will completely solve your problem (you may need to fix the socket path as suggested by cababunga), but try 127.0.0.1 to bypass the socket connection and establish a TCP one.

like image 37
Pekka Avatar answered Sep 20 '22 15:09

Pekka