3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQL 8が起動しないエラーの原因と解決策

Last updated at Posted at 2019-03-11

はじめに

mysqlが起動しないエラーです。
MySql version8です。

やったこと

mysqlを起動

$ mysql -u root -p

エラー

socket '/tmp/mysql.sock' (2)を通じて、local MySQL serverに接続できない

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

試したこと

①(1)新しいファイルを作成

$ sudo touch mysql.sock
$ sudo mysql.server start

PIDファイルを更新せずにサーバーが終了する

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

①(2)新しいファイル作成

コマンドを少し変えて、試してみた。

$ sudo touch /tmp/mysql.sock

コマンド少し変えても、同じエラーがでた。

$ 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/****.local.pid).

②PIDファイルを確認

ファイルがない

$ ls -la /usr/local/var/mysql/xxxxx.local.pid
ls: /usr/local/var/mysql/xxxxx.local.pid: No such file or directory

③権限を与える

$ sudo chown -R _mysql:_mysql /usr/local/var/mysql

起動する

$ mysql -u root -p

socket '/tmp/mysql.sock' (2)を通じて、local MySQL serverに接続できないエラー。

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

④mysqlを再インストール

$ brew uninstall mysql
Uninstalling /usr/local/Cellar/mysql/8.0.15... (267 files, 234.6MB)

permission deniedと、ERROR! The server quit without updating PID fileのエラー

mysql.server start
Starting MySQL
./usr/local/Cellar/mysql@5.7/5.7.25/bin/mysqld_safe: line 144: /usr/local/var/mysql/****.local.err: Permission denied
/usr/local/Cellar/mysql@5.7/5.7.25/bin/mysqld_safe: line 144: /usr/local/var/mysql/****.local.err: Permission denied
/usr/local/Cellar/mysql@5.7/5.7.25/bin/mysqld_safe: line 198: /usr/local/var/mysql/****.local.err: Permission denied
/usr/local/Cellar/mysql@5.7/5.7.25/bin/mysqld_safe: line 144: /usr/local/var/mysql/****.local.err: Permission denied
 ERROR! The server quit without updating PID file (/usr/local/var/mysql/****.local.pid).

⑤$ brew services restart mysqlでリスタート

$ brew services restart mysql
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 0), reused 13 (delta 0), pack-reused 0
Unpacking objects: 100% (17/17), done.
Tapped 1 command (50 files, 62.6KB).
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

$ mysql.server start

$ mysql.server start
Starting MySQL
 SUCCESS! 
`
`
`
$ 2019-03-17T04:54:20.6NZ mysqld_safe A mysqld process already exists

$ mysql -u root -p

$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

リスタートしてみて、サーバー立ち上げてみたら、SUCCESSになった。$ mysql -u root -p したけど、ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)のエラーが出た。

参考記事:
https://sankame.github.io/blog/2017-11-20-fail_to_connect_mysql/

$ mysqld_safe --skip-grant-tables &

参考記事:https://qiita.com/unbabel/items/b784459356686641dabe

$ mysqld_safe --skip-grant-tables &
[1] 8341
***noMacBook-puro:contents_app ****$ 2019-03-17T05:14:10.6NZ mysqld_safe Logging to '/usr/local/var/mysql/***noMacBook-puro.local.err'.
2019-03-17T05:14:10.6NZ mysqld_safe A mysqld process already exists

mysql -u root

mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 Homebrew

Copyright (c) 2000, 2019, 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.

use mysql;

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

UPDATE user SET Password=PASSWORD('mynewpassword') WHERE User='root';

mysql> UPDATE user SET Password=PASSWORD('mynewpassword') WHERE User='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('mynewpassword') WHERE User='root'' at line 1

■エラーコード:1064
■SQLSTATE:42000
■エラーメッセージ例:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near [入力したSQL文の一部].
■エラーの原因:
SQLの文法に誤りがある。
■エラーへの対処法:
MySQLのバージョンとマニュアルを確認し、SQL文を見直す。 こちらもクォーテーションなど区切り文字には注意が必要。
引用元:http://proengineer.internous.co.jp/content/columnfeature/7054#section206

ということなので、
UPDATE user SET Password=PASSWORD('mynewpassword') WHERE User='root';の文法に誤りがあることがエラーの原因。

ALTER USER 'root'@'localhost' identified BY 'hoge';でmysqlのrootのパスワードを変更。

参照記事:http://www-creators.com/archives/5574

mysql > ALTER USER 'root'@'localhost' identified BY 'hoge';
Query OK, 0 rows affected (0.01 sec)

exitした後に、mysqlを再び起動

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.15 Homebrew

Copyright (c) 2000, 2019, 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起動できた。

パスワード変更時のエラーの原因

UPDATE user SET Password=PASSWORD('mynewpassword') WHERE User='root';のPASSWORD('mynewpassword')の()の関数は、MySQL version 5.67までしか使用できない。

MySQL 8では、ALTER USER 'root'@'localhost' identified BY 'hoge';でパスワードを変更する。

終わりに

$ brew services restart mysql
してから、
$ mysql.server start
でmysqlが起動しました。次に、
$ mysql -u root -pをやると、mysqlの文法エラーにぶつかりました。
このエラーは、MySqlのversion8の文法の表記のコマンドで解決できました。解決後、mysqlを起動のコマンドを打つと、無事、起動できました。

原因に対する考察

$sudo mysql.server restartでサーバーは立ち上がらず、$ brew services restart mysqlをすると、サーバーが立ち上がったのかについて、あくまでも初心者の推測ですが、何らかの理由で、$ brew services restart mysqlで、MySQLを自動起動する必要があったみたいです。なぜ、自動起動しないとMySQLが起動しなかったのか、考えていきたいです。

・参照記事
https://qiita.com/_natsu_no_yuki_/items/ae4c94187093e4ab3cdc
https://qiita.com/carotene4035/items/e00076fe3990b9178cc0
https://qiita.com/hondy12345/items/d32ed749fb49e9da7de6
https://qiita.com/fujitora/items/d341c52706d1954cae28
https://cockscomb.hatenablog.com/entry/2014/04/05/153451

3
6
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
3
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?