MySQL

socketのエラーでmysqlが起動できない時

毎度毎度のこと、mysqlの起動ができなくなってあたふたしてます。

% sudo mysql.server restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/fukaminmin.local.pid).

はい。よくありますね。

あーもう!ってなりますが、ちゃんとエラーログを見ましょう!!!
マジで!
マジで!
マジで!

とりあえずエラーログを追ってみる

tail -f /usr/local/var/mysql/fukaminmin.local.err

なげーよ!!!!!!!!!
って思いますが、エラーの部分を見てみましょう
下のところで言うと、下から三つ目くらいから[ERROR]ってなってますね!

2017-12-26T06:27:41.6NZ mysqld_safe Logging to '/usr/local/var/mysql/fukaminmin.local.err'.
2017-12-26T06:27:41.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-12-26T06:27:41.725406Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2017-12-26T06:27:41.725679Z 0 [Note] /usr/local/Cellar/mysql/5.7.20/bin/mysqld (mysqld 5.7.20) starting as process 39732 ...
2017-12-26T06:27:41.729182Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2017-12-26T06:27:41.731152Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-12-26T06:27:41.731194Z 0 [Note] InnoDB: Uses event mutexes
2017-12-26T06:27:41.731209Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2017-12-26T06:27:41.731220Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-12-26T06:27:41.731628Z 0 [Note] InnoDB: Number of pools: 1
2017-12-26T06:27:41.731818Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-12-26T06:27:41.733362Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2017-12-26T06:27:41.746110Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-12-26T06:27:41.765053Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-12-26T06:27:41.773305Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-12-26T06:27:41.773438Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2017-12-26T06:27:41.792898Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2017-12-26T06:27:41.793729Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-12-26T06:27:41.793762Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-12-26T06:27:41.793974Z 0 [Note] InnoDB: Waiting for purge to start
2017-12-26T06:27:41.846194Z 0 [Note] InnoDB: 5.7.20 started; log sequence number 2565491
2017-12-26T06:27:41.846522Z 0 [Note] InnoDB: Loading buffer pool(s) from /usr/local/var/mysql/ib_buffer_pool
2017-12-26T06:27:41.846702Z 0 [Note] Plugin 'FEDERATED' is disabled.
2017-12-26T06:27:41.849219Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171226 15:27:41
2017-12-26T06:27:41.855008Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2017-12-26T06:27:41.855042Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2017-12-26T06:27:41.855834Z 0 [Warning] CA certificate ca.pem is self signed.
2017-12-26T06:27:41.855906Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2017-12-26T06:27:41.862724Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2017-12-26T06:27:41.862774Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2017-12-26T06:27:41.862893Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2017-12-26T06:27:41.863050Z 0 [ERROR] Could not create unix socket lock file /var/lib/mysql/mysql.sock.lock.
2017-12-26T06:27:41.863067Z 0 [ERROR] Unable to setup unix socket lock file.
2017-12-26T06:27:41.863079Z 0 [ERROR] Aborting

最初はsock.lockってなってるよおいおいなんだこれって思いましたが、
単純にmysqlが.sock.sockが作れないよ!って言われてるので、フォルダの権限を変更しました。

sudo chown fukaminmin /var/lib/mysql

そうするとあっさり起動。なんだったんだよぉおおおおお。

% mysql.server start
Starting MySQL
. SUCCESS!