0

Working on a Ubuntu 22.04 system with MySQL 8. I have a legacy collection of MySQL data/dbs on an external harddrive that I used a Docker container and MySQL image to connect to and export. This worked fine, but when I attempt to connect to my existing MySQL installation via command line I'm getting the following error despite the server showing as 'active' via systemctl:

chris@chris-X1C6:~$ mysql -u admin -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I've googled and found a few (and this) remedies, none of which fix the issue. System restart doesn't address either.

As a first common sense check, I don't see a mysql sock file in the /tmp location referenced, but do see one (mysqld.sock) located in the /var/run/mysqld directory. I also don't see a .cnf file to inspect in the mysql directory (/var/lib/mysql).

What else should I be looking at?

4
  • Check if the mysql process is running (ps ax | grep mysql). looks like you can use the --socket option, the MYSQL_UNIX_PORT environment variable, or various .cnf files to get mysql to check a different socket path. Since the command looks like it's checking a non-default path, maybe docker or some other process updated that env?
    – Cpt.Whale
    Commented Jan 26 at 20:58
  • @Cpt.Whale The server is running. Only see an auto.cnf file (and has no directory related to one in question). Do you know what the default path is supposed to be? Possible Docker altered this I suppose (and the source of the issue, as this worked until I used Docker and MySQL image)
    – Chris
    Commented Jan 27 at 0:34
  • The default directory is where the sock file currently exists: /var/run/mysqld/mysqld.sock. The mysql command error says it's checking for /tmp/mysql.sock, so I'm curious if set | grep MYSQL shows something unexpected. You might just need to link it like ln -s /private/var/mysql/mysql.sock /tmp/mysql.sock like in the answer here: stackoverflow.com/a/18418296/7411885 there are some other good troubleshooting steps in there as well
    – Cpt.Whale
    Commented Jan 29 at 16:40
  • @Cpt.Whale thanks, bud...nothing interesting output from the set... call. I theorize Docker changed some default directory where the sock file is being referenced (ie, from default /var/run... to the /tmp location)...nothing turned up doing a find for the location, do you know where the socket directory is specified in some mysql config file so I can change it back to where it actually exists?
    – Chris
    Commented Jan 29 at 19:57

1 Answer 1

0

The docs mention that the default location for the Unix socket file that the server uses for communication with local clients is /tmp/mysql.sock. (For some distribution formats, the directory might be different, such as /var/lib/mysql for RPMs.)


Try the troubleshooting steps here: https://dev.mysql.com/doc/refman/8.0/en/problems-with-mysql-sock.html

  • Specify the path in a global or local option file. For example, put one or both of the following lines in /etc/my.cnf to set the server or client-side paths:
[mysqld]
socket=/path/to/socket

[client]
socket=/path/to/socket
  • Specify a --socket option on the command line to mysql clients like mysql or mysqladmin --socket=/path/to/socket
  • Set the MYSQL_UNIX_PORT environment variable to the path of >the Unix socket file.

You can test whether the new socket location works by attempting to connect to the server with this command:

$> mysqladmin --socket=/path/to/socket version

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .