LoginSignup
0
0

More than 3 years have passed since last update.

Debian系でMySQLに接続できない時のエラー解決方法

Last updated at Posted at 2019-06-08

環境

  • OS:Kali Linux 2019.2
  • MySQL:Ver 15.1 Distrib 10.3.15-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

問題

以下のように、
MySQLに接続しようとするとエラーが発生する。

# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

原因

MySQLクライアントが呼び出す
UNIXドメインソケットと、
MySQLサーバーが呼び出す
UNIXドメインソケットが異なるため。

※ UNIXドメインソケットとは、
  同一ホスト内で通信を行うためのソケット。
  実態はファイル。

解決方法

サーバーが呼び出す
UNIXドメインソケットのファイルパス名を、
クライアントに合わせて変更する。

変更前

/opt/lampp/etc/my.cnf(一部抜粋)
# The following options will be passed to all MySQL clients
[client]
socket      = /opt/lampp/var/mysql/mysql.sock

# The MySQL server
[mysqld]
socket      = /opt/lampp/var/mysql/mysql.sock

変更後

/opt/lampp/etc/my.cnf(一部抜粋)
# The following options will be passed to all MySQL clients
[client]
#socket     = /opt/lampp/var/mysql/mysql.sock
socket      = /var/run/mysqld/mysqld.sock

# The MySQL server
[mysqld]
#socket     = /opt/lampp/var/mysql/mysql.sock
socket      = /var/run/mysqld/mysqld.sock
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0