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!
asked Aug 7, 2021 at 14:19

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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.