Pergunta

I've been occasionally reviewing an unsolved mystery on a Solaris 10 setup we have been running, and I noticed something in the error message that might yield a clue to help me solve the mystery.

The error message is when connecting to MySQL on a UNIX Domain Socket.

I have a specific question here, which is about the error code at the end.

See these three error messages:

  • mysql -S /tmp/missing.sock outputs
    Can't connect to local MySQL server through socket '/tmp/missing.sock' (2)

  • mysql -S /dev/null outputs
    Can't connect to local MySQL server through socket '/dev/null' (95)

  • The rare and intermittent error I am trying to resolve is
    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (146)

That number at the end: Is this a UNIX Domain Socket error code? If so, is there a place I can look up the meaning of that code?

As I said, this is a specific question. Other helpful input should be posted to the other question.

Foi útil?

Solução

The numbers in parentheses are almost certainly system error numbers, normally reported via errno, the definitions for which are found via #include <errno.h> though on Solaris the numbers are usually in /usr/include/sys/errno.h (but can be in other places, especially on Linux and Mac OS X). You could write a simple program to see the 3 errors.

#include <stdio.h>
#include <string.h>

int main(void)
{
    puts(strerror(2));
    puts(strerror(95));
    puts(strerror(146));
    return 0;
}

Conjecture: 2 is probably ENOENT, no such file or directory; 95 may be ENOTSOCK (not a socket); 146 might be ENOTSUPP (operation not supported).

George Bailey confirms:

On my system, the answer was in /usr/include/sys/errno.h:

  • 2=ENOENT
  • 95=ENOTSOCK
  • 146=ECONNREFUSED

Note that error numbers up to the mid-twenties tend to be consistent across systems as the error codes existed in 7th Edition Unix. Higher numbers diverge. For example, on Mac OS X 10.9:

  • 2 (ENOENT): No such file or directory
  • 95 (EMULTIHOP): Reserved
  • errno: no message for errno = 146
  • ENOTSOCK (38): Socket operation on non-socket
  • ECONNREFUSED (61): Connection refused

On SuSE (SLES 10 SP2 — antique, but these numbers don't change much):

  • 2 (ENOENT): No such file or directory
  • 95 (EOPNOTSUPP): Operation not supported on transport endpoint
  • errno: no message for errno = 146
  • ENOTSOCK (88): Socket operation on non-socket
  • ECONNREFUSED (111): Connection refused

These answers were obtained via a program errno that reports on error numbers and names. It has to be compiled for each different system.


Note that there is a consistent MySQL-provided component to the messages:

Can't connect to local MySQL server through socket '/dev/null' (95)

roughly as if the format string for the printf() statement was:

"Can't connect to local MySQL server through socket '%s' (%s)\n"

The name of the 'socket' file is being provided — very helpful — and (educated guess) the system error number, collected at some point from errno. However, errno is volatile — almost any library function may set it to a non-zero value — so you need to preserve a specific value (copy it) before doing much in the way of error reporting work, such as reading message files to get the correct translation of the format string.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top