MySQL:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

* "mysql.server start"をしないで mysql と打った場合も同じエラーが出ます。

 

<エラー状態>

$ mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 

$ mysql.server stop
ERROR! MySQL server PID file could not be found!

$ sudo mysql.server start

Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/Harus-MacBook-Air.local.pid).

-----------------------------------------------------

<mysqlのインストール方法>

homebrew

<mysql.sockの場所を確認> ( =>なし)

ソケットファイルのパスを/etc/my.cnfとして自分で作成し、指定しても同じ

 -----------------------------------------------------

<成功した方法>

1: MySQLをhomebrewでアンインストール

   homebrewでアンインストール

   homebrewをアップデート

   最新のmysqlをインストール

2:my.cnfファイル(それまでに他の解決策として/etc/my.cnfとして自分で作成していたもの)を消す

MySQL ERROR! The server quit without updating PID file

3: mysql.server start

....SUCCESS!

--------------------------------------------------------

<他に試された解決方法(一部)>

<mysqlをrestart> (=> できない, 上のエラー文)

 

<mysqlインスタンスが他で走っているか確認> ( => 走っていない)

ps ax | grep mysql

 

<mysqlインスタンスを消す>(=>変化なし)

kill $(pgrep mysql)

 

<touch メソッド でpidファイル作成> (=>変化なし)

mysql.server startとすると、ファイルが消えただけで同じエラー。

 

 

<touch mysql.sock でソケットファイル作成> (=>変化なし)

mysql.server startとすると、ファイルが消えただけで同じエラー。

 

<mysqlの権限を変える> (=> 変化なし)

権限の確認

➜ ls -ll
total 0
drwxr-xr-x 3 myname admin 102 Dec 16 2015 cache
drwxr-xr-x 4myname admin 136 Oct 6 21:48 homebrew
drwxr-xr-x 2myname admin 68 Nov 11 11:32 log
drwxr-xr-x 27 _mysql _mysql 918 Mar 3 15:19 mysql
drwx------ 23 myname admin 782 Mar 29 2015 postgres

 

権限の変更

➜ var sudo chown -Rmyname:admin /usr/local/var/mysql
➜ ls -ll
total 0
drwxr-xr-x 3 myname admin 102 Dec 16 2015 cache
drwxr-xr-x 4 myname admin 136 Oct 6 21:48 homebrew
drwxr-xr-x 2 myname admin 68 Nov 11 11:32 log
drwxr-xr-x 27 myname admin 918 Mar 3 15:19 mysql
drwx------ 23 myname admin 782 Mar 29 2015 postgres

 

<MySQLd を起動> (=> エラー)

$ mysqld start

2017-03-03 15:19:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-03 15:19:57 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2017-03-03 15:19:57 0 [Note] mysqld (mysqld 5.6.34) starting as process 25611 ...
2017-03-03 15:19:57 25611 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2017-03-03 15:19:57 25611 [Note] Plugin 'FEDERATED' is disabled.
2017-03-03 15:19:57 25611 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-03-03 15:19:57 25611 [Note] InnoDB: The InnoDB memory heap is disabled
2017-03-03 15:19:57 25611 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-03-03 15:19:57 25611 [Note] InnoDB: Memory barrier is not used
2017-03-03 15:19:57 25611 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-03-03 15:19:57 25611 [Note] InnoDB: Using CPU crc32 instructions
2017-03-03 15:19:57 25611 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-03-03 15:19:57 25611 [Note] InnoDB: Completed initialization of buffer pool
2017-03-03 15:19:57 25611 [Note] InnoDB: Highest supported file format is Barracuda.
InnoDB: No valid checkpoint found.
InnoDB: If you are attempting downgrade from MySQL 5.7.9 or later,
InnoDB: please refer to http://dev.mysql.com/doc/refman/5.6/en/upgrading-downgrading.html
InnoDB: If this error appears when you are creating an InnoDB database,
InnoDB: the problem may be that during an earlier attempt you managed
InnoDB: to create the InnoDB data files, but log file creation failed.
InnoDB: If that is the case, please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/error-creating-innodb.html
2017-03-03 15:19:57 25611 [ERROR] Plugin 'InnoDB' init function returned error.
2017-03-03 15:19:57 25611 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
mysqld: Too many arguments (first extra is 'start').
Use --verbose --help to get a list of available options
2017-03-03 15:19:57 25611 [ERROR] Aborting

2017-03-03 15:19:57 25611 [Note] Binlog end
2017-03-03 15:19:57 25611 [Note] Shutting down plugin 'partition'
...
2017-03-03 15:19:57 25611 [Note] mysqld: Shutdown complete

 

 

<試す可能性のある方法>

<(sockファイルがある場合)mysql.sockのパスをリンクさせる> 

If you find the same file in another location then symlink it:

For ex: I have it in /data/mysql_datadir/mysql.sock

Switch user to mysql and execute as mentioned below:

su mysql

ln -s /data/mysql_datadir/mysql.sock /var/lib/mysql/mysql.sock