MySQLにログインしようとすると「ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)」というエラーが出力される
こんにちは、KUJIRAです。この前MySQLを利用しようとしたらエラーが出力されたのでメモを取ります。
事象
MySQLにログインしょうとすると「ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)」というエラーが出力される。
[root@localhost ~]# mysql -u root -pmysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [root@localhost ~]#
原因
msql.sockというのに接続できないのが問題です。MySQLが起動していない可能性があるので確認します。
[root@localhost ~]# systemctl status mysqld.service mysqld.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead) [root@localhost ~]#
想像の斜め上を行く結果です。MySQLがインストールされていませんw
対処
ということでインストールします。最近MySQLはMariaDBという形で名前を変えました・・・というかフォークしました。MySQL自身はオラクルのものなのでみんな嫌がって離れて行ったのでしょうか・・・謎です。
- MariaDBがちゃんとリポジトリにあるかの確認
[root@localhost ~]# yum info mariadb-server 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.fairway.ne.jp * extras: mirror.fairway.ne.jp * updates: ftp.riken.jp 利用可能なパッケージ 名前 : mariadb-server アーキテクチャー : x86_64 エポック : 1 バージョン : 5.5.41 リリース : 2.el7_0 容量 : 11 M リポジトリー : base/7/x86_64 要約 : The MariaDB server and related files URL : http://mariadb.org ライセンス : GPLv2 with exceptions and LGPLv2 and BSD 説明 : MariaDB is a multi-user, multi-threaded SQL database server. It is a : client/server implementation consisting of a server daemon (mysqld) : and many different client programs and libraries. This package contains : the MariaDB server and some accompanying files and directories. : MariaDB is a community developed branch of MySQL. [root@localhost ~]#
- MariaDBのインストール
[root@localhost ~]# yum -y install mariadb-server 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.fairway.ne.jp * extras: mirror.fairway.ne.jp * updates: ftp.riken.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ mariadb-server.x86_64 1:5.5.41-2.el7_0 を インストール --> 依存性の処理をしています: perl-DBI のパッケージ: 1:mariadb-server-5.5.41-2.el7_0.x86_64 --> 依存性の処理をしています: perl-DBD-MySQL のパッケージ: 1:mariadb-server-5.5.41-2.el7_0.x86_64 --> 依存性の処理をしています: perl(DBI) のパッケージ: 1:mariadb-server-5.5.41-2.el7_0.x86_64 --> トランザクションの確認を実行しています。 ---> パッケージ perl-DBD-MySQL.x86_64 0:4.023-5.el7 を インストール ---> パッケージ perl-DBI.x86_64 0:1.627-4.el7 を インストール --> 依存性の処理をしています: perl(RPC::PlServer) >= 0.2001 のパッケージ: perl-DBI-1.627-4.el7.x86_64 --> 依存性の処理をしています: perl(RPC::PlClient) >= 0.2000 のパッケージ: perl-DBI-1.627-4.el7.x86_64 --> トランザクションの確認を実行しています。 ---> パッケージ perl-PlRPC.noarch 0:0.2020-14.el7 を インストール --> 依存性の処理をしています: perl(Net::Daemon) >= 0.13 のパッケージ: perl-PlRPC-0.2020-14.el7.noarch --> 依存性の処理をしています: perl(Net::Daemon::Test) のパッケージ: perl-PlRPC-0.2020-14.el7.noarch --> 依存性の処理をしています: perl(Net::Daemon::Log) のパッケージ: perl-PlRPC-0.2020-14.el7.noarch --> 依存性の処理をしています: perl(Compress::Zlib) のパッケージ: perl-PlRPC-0.2020-14.el7.noarch --> トランザクションの確認を実行しています。 ---> パッケージ perl-IO-Compress.noarch 0:2.061-2.el7 を インストール --> 依存性の処理をしています: perl(Compress::Raw::Zlib) >= 2.061 のパッケージ: perl-IO-Compress-2.061-2.el7.noarch --> 依存性の処理をしています: perl(Compress::Raw::Bzip2) >= 2.061 のパッケージ: perl-IO-Compress-2.061-2.el7.noarch ---> パッケージ perl-Net-Daemon.noarch 0:0.48-5.el7 を インストール --> トランザクションの確認を実行しています。 ---> パッケージ perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 を インストール ---> パッケージ perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 を インストール --> 依存性解決を終了しました。 依存性を解決しました =================================================================================================================================================================================================================================== Package アーキテクチャー バージョン リポジトリー 容量 =================================================================================================================================================================================================================================== インストール中: mariadb-server x86_64 1:5.5.41-2.el7_0 base 11 M 依存性関連でのインストールをします: perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k perl-DBD-MySQL x86_64 4.023-5.el7 base 140 k perl-DBI x86_64 1.627-4.el7 base 802 k perl-IO-Compress noarch 2.061-2.el7 base 260 k perl-Net-Daemon noarch 0.48-5.el7 base 51 k perl-PlRPC noarch 0.2020-14.el7 base 36 k トランザクションの要約 =================================================================================================================================================================================================================================== インストール 1 パッケージ (+7 個の依存関係のパッケージ) 総ダウンロード容量: 12 M インストール容量: 59 M Downloading packages: (1/8): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00 (2/8): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:01 (3/8): perl-DBD-MySQL-4.023-5.el7.x86_64.rpm | 140 kB 00:00:01 (4/8): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:01 (5/8): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00 (6/8): perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:14 (7/8): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00 (8/8): mariadb-server-5.5.41-2.el7_0.x86_64.rpm | 11 MB 00:02:28 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 合計 83 kB/s | 12 MB 00:02:28 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/8 インストール中 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 2/8 インストール中 : perl-IO-Compress-2.061-2.el7.noarch 3/8 インストール中 : perl-Net-Daemon-0.48-5.el7.noarch 4/8 インストール中 : perl-PlRPC-0.2020-14.el7.noarch 5/8 インストール中 : perl-DBI-1.627-4.el7.x86_64 6/8 インストール中 : perl-DBD-MySQL-4.023-5.el7.x86_64 7/8 インストール中 : 1:mariadb-server-5.5.41-2.el7_0.x86_64 8/8 検証中 : perl-Net-Daemon-0.48-5.el7.noarch 1/8 検証中 : 1:mariadb-server-5.5.41-2.el7_0.x86_64 2/8 検証中 : perl-IO-Compress-2.061-2.el7.noarch 3/8 検証中 : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 4/8 検証中 : perl-PlRPC-0.2020-14.el7.noarch 5/8 検証中 : perl-DBI-1.627-4.el7.x86_64 6/8 検証中 : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 7/8 検証中 : perl-DBD-MySQL-4.023-5.el7.x86_64 8/8 インストール: mariadb-server.x86_64 1:5.5.41-2.el7_0 依存性関連をインストールしました: perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-5.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 完了しました! [root@localhost ~]#
- MariaDBのステータス確認
[root@localhost ~]# systemctl status mariadb.service mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled) Active: inactive (dead) [root@localhost ~]#
- MariaDBの起動
[root@localhost ~]# systemctl start mariadb.service [root@localhost ~]# [root@localhost ~]# systemctl status mariadb.service mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled) Active: active (running) since 水 2015-08-19 21:52:12 JST; 11s ago Process: 78623 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 78541 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 78620 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─78620 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─78777 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mys... 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: The latest information about MariaDB is available at http://mariadb.org/. 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: You can find additional information about the MySQL part at: 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: http://dev.mysql.com 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: Support MariaDB development by buying support/new features from MariaDB 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: Corporation Ab. You can contact us about this at sales@mariadb.com. 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: Alternatively consider joining our community based development effort: 8月 19 21:52:09 localhost.localdomain mariadb-prepare-db-dir[78541]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/ 8月 19 21:52:09 localhost.localdomain mysqld_safe[78620]: 150819 21:52:09 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 8月 19 21:52:09 localhost.localdomain mysqld_safe[78620]: 150819 21:52:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 8月 19 21:52:12 localhost.localdomain systemd[1]: Started MariaDB database server. [root@localhost ~]#
起動されていることが確認された。
- MariaDBへのログイン
[root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.41-MariaDB MariaDB Server Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
無事ログインを確認
ログインできました。なんか色々と勉強になったエラーでした。。。一番勉強になったのはMariaDBですね。。。ということで今日はここまでKUJIRAでした。