LoginSignup
52

More than 5 years have passed since last update.

「ERROR! The server quit without updating PID file」となり、MacOSでmysqlにアクセスできない。

Posted at

「ERROR! The server quit without updating PID file」となり、MacOSでmysqlにアクセスできない。

【事象】

mysqlにアクセスしようとして、 $ mysql -u root とかって打ち込んでも、 command not found となる。

【原因仮説】

おそらくmysqlへのアクセスのパスが通っていないのが原因と思われる。(mysqlの存在するディレクトリまでアクセスできていない。)←となると、mysqlの存在するディレクトリの場所を特定して、パスを通せばいいのでは?

【解決経緯】

①普通にmysql起動できるか確かめる。

$ brew info mysql と打ち込むと、

mysql: stable 5.7.18 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
Conflicts with:
  mariadb (because mysql, mariadb, and percona install the same binaries.)
  mariadb-connector-c (because both install plugins)
  mysql-cluster (because mysql, mariadb, and percona install the same binaries.)
  mysql-connector-c (because both install MySQL client libraries)
  percona-server (because mysql, mariadb, and percona install the same binaries.)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✘
==> Requirements
Required: macOS >= 10.7 ✔
==> Options
--with-archive-storage-engine
        Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
        Compile with the BLACKHOLE storage engine enabled
--with-debug
        Build with debug support
--with-embedded
        Build the embedded server
--with-local-infile
        Build with local infile loading support
--with-test
        Build with unit tests
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
    mysql -uroot
To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

と帰ってきたので、普通に $ mysql.server start と打ち込んでみるも、 command not found となる。やはりパスが通らずアクセスが出来ない。

②mysqlをbrewで再インストールする

$ brew install mysql で再度mysqlをインストールすると ==> Summary
🍺 /usr/local/Cellar/mysql/5.7.19: 322 files, 234.8MB

となったため、 $ cd /usr/local/Cellar/mysql でmysqlに移動し、 $ mysql.server start と打ち込むと

Starting MySQL
. SUCCESS! 

きたー!!
これでmysqlの起動はできた。
ここで謎に

To have launchd start mysql now and restart at login:
brew services start mysql

となっていたから、 $ brew services start mysql と打ってみると、mysqlの起動がずっと待ち状態になって接続できなくなった…。

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

↑こんな感じで接続待たされて、結局接続できないという。仕方ないので今度はmysql5.6でインストールして起動してみることに。

http://cyborg-ninja.com/ittips/624
↑を参考に、mysqlを削除していって、再度mysqlをインストール。

http://easyramble.com/mysql-server-pid-file-error.html
↑を参考に、 $ ps -ef | grep mysql して、PIDを指定して、 sudo kill -9 PID してmysql再度startさせてみるも、特に変化なし。

http://nekonenene.hatenablog.com/entry/2016/04/01/194157
↑を参考に、 /usr/local/etc ディレクトリにある「my.cnf」の設定を変えようと試みる。設定を変えてみるものの、変化なし…。

http://otiai10.hatenablog.com/entry/2014/03/15/190134
↑よくわかんないけど、参考にして「$ cd . ; sudo /usr/local/opt/mysql/bin/mysqld_safe &」と打ってみる。→変化なし。

http://qiita.com/t_oginogin/items/76ca2b6ce18d53988dc3

一度でも5.7を起動してしまうと、同じデータを使って5.6を起動すると次のようなエラーが出るようになります。

Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/ogin.local.pid).
mysqld等は動いていなかったので権限周りと思われますが、うまく解決できませんでした。
(バージョンによってディレクトリ構成が違っていたので、権限以外にも何か影響しているのかもしれません)

一度mysql5.7にアクセスして、その後5.6のものにもアクセスしようとしているからダメなのかということで、localにあるmysql関連の全てを削除してから、brewで再インストールしようということで、

③local配下のmysql全て削除してmysqlインストール

$ sudo rm -rf /usr/local/mysql
$ sudo rm -rf /Library/StartupItems/MYSQL
$ sudo rm -rf /Library/PreferencePanes/MySQL.prefPane
$ sudo rm -rf /Library/Receipts/mysql-.pkg
$ sudo rm -rf /usr/local/Cellar/mysql*
$ sudo rm -rf /usr/local/bin/mysql*
$ sudo rm -rf /usr/local/var/mysql*
$ sudo rm -rf /usr/local/etc/my.cnf
$ sudo rm -rf /usr/local/share/mysql*
$ sudo rm -rf /usr/local/opt/mysql*
を実行し、 $ brew install mysql56 で再度mySQLのバージョン5.6をインストール。

Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.6-5.6.37.el_capitan.bottle.tar.gz
Already downloaded: /Users/ryosaito/Library/Caches/Homebrew/mysql@5.6-5.6.37.el_capitan.bottle.tar.gz
==> Pouring mysql@5.6-5.6.37.el_capitan.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.6/5.6.37/bin/mysql_install_db --verbose --user=ryosaito --basedir=/usr/local/Cellar/mysql@5.6/5.6.37 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

MySQL is configured to only allow connections from localhost by default

To connect:
    mysql -uroot

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.6/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/mysql@5.6/lib
    CPPFLAGS: -I/usr/local/opt/mysql@5.6/include

To have launchd start mysql@5.6 now and restart at login:
  brew services start mysql@5.6
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.6/bin/mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql@5.6/5.6.37: 346 files, 154.8MB

出てきた説明を読んでみると、

If you need to have this software first in your PATH run:
echo ‘export PATH=“/usr/local/opt/mysql@5.6/bin:$PATH”’ >> ~/.bash_profile

って言われてるので、 $ echo 'export PATH="/usr/local/opt/mysql@5.6/bin:$PATH"' >> ~/.bash_profile と打ち込み、 $ /usr/local/opt/mysql@5.6/bin/mysql.server start とすると…

Starting MySQL
. SUCCESS! 

きたー!!ついに起動できました。

$ /usr/local/opt/mysql@5.6/bin/mysql -u root で、

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.37 Homebrew
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

ようやくmysql入れた〜。いやはや長かった。

http://qiita.com/owlbeck/items/fff7125d3f56dfde8b50
↑これも参考にすると、mysqlへのパスが通っていなかったことが問題だったのかな。

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
52