[MariaDB/MySQL] 로컬호스트 접속 오류 #1

2023. 4. 30. 02:28리눅스 실제 사용 팁/Maria DB

localhost 에서 운영 중인 DB 에 접속시도할 때 다음과 같이 소켓을 못찾는 오류가 뜰 때가 있다.

혹자는 로그에 기록된 (mariadb의) root 계정의 임의 생성된 패스워드를 찾아서 지정하면 된다는데

바이너리 타볼로 직접 설치한 내 Maria DB 로그에서는 password 라는 단어를 도무지 찾을 수 없었다.

 

$ mariadb
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

 

익숙치 않거나 불편한 오류 메시지를 보면, (마치 윈도에서 발생하는 0x????? 메시지처럼), 원인 분석도 안한 체 그냥 귀찮아서

어떻게든 구글링하다가 포기하게 될 때가 잦다.

 

위의 메시지는 MariaDB 또는 MySQL DB 를 실행할 때 생성되는 소켓파일을 못찾아서 발생한다.

소켓의 위치를 알면 커맨드라인 클라이언트의 -S 옵션 뒤에 경로를 붙여 주면 된다.

 

$ sudo bin/mariadbd-safe --user=mariadb
---
(결과)
[sudo] user 암호: 
230430 00:28:20 mysqld_safe Logging to '/home/user/__Applications/mariadb/data/jhiz.err'.
230430 00:28:20 mysqld_safe Starting mariadbd daemon with databases from /home/user/__Applications/mariadb/data

(설명)
아직 시스템 서비스로 등록안한 관계로 직접 실행하고 있다.

첫 번쨰 로그 메시지를 보면 mariadb/data/jhiz.err 에 로그를 기록한다고 나온다.
로그 파일은 각자 PC 설정에 따라 파일명이 다를 수 있다.

 

Maria DB 실행 로그파일에서 socket 으로 검색했더니 /tmp/mysql.sock 으로 나온다.

$ mariadb -S /tmp/mysql.sock
---
(결과: 계정 및 패스워드 없이 소켓 위치만 지정해도 반가운 로그인 프롬프트가 나온다. 일하자!)

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.11.2-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

 

 

참고한 사이트 :

https://blog.naver.com/islove8587/221970366883