인디노트

MySQL 의 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 본문

개발 플랫폼 및 언어/DB 기술

MySQL 의 Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

인디개발자 2021. 4. 14. 09:58

MySQL 서버를 설치 한 후 sock 파일을 다른 곳으로 이동한 후 mysql 접속을 할 때 다음과 같은 에러 메시지가 나오면서 접속을 못하는 경우가 발생합니다.

 

mysql -u root -p
Enter password:

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

 

이 경우 아마 mysql-server.cnf 파일에 다음과 같이 socket 디렉토리를 옮긴 경우일 것입니다.

[mysqld]
datadir=/DATA/mysql
socket=/DATA/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

 

이렇게 가동된 서버를 로그온 하기 위해서는 client 의 socket 관련 설정을 해야 합니다. 다음과 같이 client.cnf 파일의 socket 관련 내용을 같은 디렉토리 패스로 설정한 후 접속하면 됩니다.

#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#


[client]
socket = /DATA/mysql/mysql.sock


# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]

 

 

 

 

반응형
Comments