CentOS 7 : cannot create thesql.sock

centosMySQLsystemd

I've installed MySQL on CentOS 7. It looks fine, start mysqld service and change root password:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

There's no "mysql.sock" in /var/lib/mysql.
I found mysql.sock in /tmp but it's not accessible.
After searching google, I found that "mysql.sock" is automatically created when mysqld start. But it doesn't work. Restart, reinstall… many times.

$ service mysqld status -l
Redirecting to /bin/systemctl status  -l mysqld.service
mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
   Active: activating (start-post) since Fri 2015-02-13 08:41:14 ICT; 4s ago
  Process: 13001 ExecStart=/usr/bin/mysqld_safe (code=exited, status=0/SUCCESS)
  Process: 12989 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 13001 (code=exited, status=0/SUCCESS);         : 13002 (mysql-systemd-s)
   CGroup: /system.slice/mysqld.service
           └─control
             ├─13002 /bin/bash /usr/bin/mysql-systemd-start post
             └─13192 sleep 1

Feb 13 08:41:14 localhost.localdomain systemd[1]: Starting MySQL Community Server...
Feb 13 08:41:14 localhost.localdomain mysqld_safe[13001]: 150213 08:41:14 mysqld_safe Logging to '/var/log/mysqld.log'.
Feb 13 08:41:14 localhost.localdomain mysqld_safe[13001]: 150213 08:41:14 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Feb 13 08:41:14 localhost.localdomain mysqld_safe[13001]: rm: cannot remove ‘**/tmp/mysql.sock’: Permission denied**
Feb 13 08:41:15 localhost.localdomain mysqld_safe[13001]: 150213 08:41:15 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

Change permission of mysql.sock:

chmod: cannot operate on dangling symlink

Best Answer

The "mysql.sock" is a unix socket, for exchanging data between processes. The alternative would be to configure it to run listening on the network.

mysqld should be creating and removing this socket as necessary. What have you done here? Did you install it with rpm from CentOS? A tarball compiled and make installed? It looks like you did something funny here. What you posted above does not look like it came from a CentOS rpm to me, unless they've changed things. This is a configuration issue for sure.

What does your my.cnf say? /var/lib/mysql/mysql.sock (I'm assuming yes) or /tmp/mysql.sock ?

file /tmp/mysql.sock

What does that say?

rpm -ql name-of-mysql-server-package

And that?

Also, contents of the my.cnf file and anything in /etc/sysconfig

Related Topic