1

I have gone over dozens of articles related to such issues without solving mine.

MySQL 8 over CentOS 8, my.cnf file indicate the socket as following:

[mysqld]

datadir=/data/mysql8/mysql
socket=/data/mysql8/mysql/mysql.sock

But when I try to connect, mysql detect the old location of datadir of socket file:

[root@db0 ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

While the running is mysql-server not mysql-client and the only config file used is the one mentioned in the question (only /etc/my.cnf exists and all other files are not).

[root@db0 ~]# /sbin/mysqld  --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 

Also when I check the mysql config, I can see the wrong dir of socket file being selected.

[root@db0 ~]# mysqladmin variables
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!

1 Answer 1

2

You have defined where the socket file is for the server in the mysqld option group, but you haven't told the mysql client where to look, so it's just using the default.

It's better to put the socket setting in the client-server option group than in the mysqld option group. This is read by both the client and the server, so then you only have to define it once.

1
  • Never thought the solution would be as simple as this, it works perfectly, Thanks!
    – Eng7
    Commented Aug 8, 2021 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.