Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13) as non-root user

Can't connect to a local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

I am getting this message, but only when I am not logged in as root.

How come not everyone has access to mysql?

It doesn't work on user htorrent, and it works as root. I tried giving sudo permission, but it doesn't work. I am on the CENTOS 6.10 (final) version.

usermod -aG wheel htorrent

I tried the following, but it doesn't work. How do I give every user access to mysql?


Solution 1:

The problem is caused by the socket having permissions which do not allow other users than root to connect to this socket. Please adjust the permissions of the socket in the mysql server configuration (most of the time its my.cnf somewhere in /etc ) or check the group that the socket is owned by, and add this user to this group, also remember to set appropriate group permissions in the configuration.

ls -la /var/lib/mysql/mysql.sock will show you the permissions and owner of the socket