1
1

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 1 year has passed since last update.

HomebrewにてインストールしたMySQLのバージョンを5.7から8.0へバージョンアップさせた方法

Last updated at Posted at 2023-02-21

はじめに

Homebrewにてインストール済みであったMySQLのVer5.7を8.0へアップデートしようとしましたが、結構苦戦したので備忘録兼同じような方の少しでも参考になればと思い記事いたします。

対象者

この記事は下記のような人を対象にしています。

  • 駆け出しエンジニア
  • プログラミング初学者
  • Homebrewにて、MySQLのVerを5.7から8.0へバージョンアップしたい方

(前提)Ver5.7をインストールした方法

Ver8.0へアップデートを試す

参考記事
【homebrew】MacのMySQLを5.6から8.0に更新 - Qiita

  • 現在のバージョンの確認
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.39, for osx10.17 (x86_64) using  EditLine wrapper
  • Homebrewの更新
$ brew update
  • mysqlを8.0.32に更新(2023/2/18時点)
$ brew install mysql
  • mysqlのバージョン確認
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.39, for osx10.17 (x86_64) using  EditLine wrapper

⇨確認するも、バージョンは5.7.39のまま(失敗)

上記からさらに試したこと

プロセスの削除

  • プロセスを確認し、grep mysql以外のプロセスを削除する
# プロセスの確認
$ ps ax | grep mysql
44146   ??  S      0:00.03 /bin/sh /usr/local/Cellar/mysql@5.6/5.6.47/bin/mysqld_safe
44255   ??  S      0:09.04 /usr/local/Cellar/mysql@5.6/5.6.47/bin/mysqld --basedir=/usr/local/Cellar/mysql@5.6/5.6.47
84116 s000  S+     0:00.00 grep mysql
    
# プロセスの削除
$ kill -9 44146
$ kill -9 44255
  • バージョンの確認
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.39, for osx10.17 (x86_64) using  EditLine wrapper

⇨これでもバージョン変わらず(失敗)

エラー:「ERROR! The server quit without updating PID file(/opt/homebrew/var/mysql/(ユーザー名).local.pid).」の解消

  • 上記実施後の状態で、mysqlを起動しようとするとエラーとなった
$ mysql.server start
Starting MySQL.. 
ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/(ユーザー名).local.pid).
  • このエラー解消をするために以下記事参考に実施
    【MySQL】[Mysql ERROR! The server quit without updating PID file]

  • エラー内容に記載のファイルを探すが該当ファイルなし

  • 代わりに同階層(/opt/homebrew/var/mysql)に似たようなファイル(ユーザー名).local.errを発見上記ファイルの中身を確認。
    かなりの分量あるがERRORで検索をかけ、一番下に記載の最新のエラー内容を確認
    MySQL_VersionUp_image1.png

    和訳すると、「ソケットで既に別のmysqldサーバーが動作していませんか?」とのことのため、該当のファイルが存在していることが原因?と推測。該当ファイルを削除してみる。

$ cd /tmp

$ ls
com.apple.launchd.AegnMCcQgE	mysql.sock.lock			mysqlx.sock.lock
mysql.sock			mysqlx.sock			powerlog
    
$ rm -f mysql.sock
rm: mysql.sock: Permission denied     # 権限がないとのエラーメッセージにつきsudoにて再実施
    
$ sudo rm mysql.sock
Password:              # パスワードはPCログイン時のパスワードを入力
    
$ ls
com.apple.launchd.AegnMCcQgE	mysql.sock.lock	  powerlog       # 無事削除成功
  • 再度SQLを起動し、ログインを試みる
$ mysql.server start
Starting MySQL
 SUCCESS!            # SQL起動は成功

$ mysql --user=root --password
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>              # ログインは無事成功。
  • ただ、SQLのバージョンを確認するとまだ5.7.39のまま
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.39, for osx10.17 (x86_64) using  EditLine wrapper

アンインストール後、再度インストール

  • 8.0にするため、一旦アンインストールし再インストールを試みる
    • SQLを一旦ストップする

      $ brew services stop mysql
      Stopping `mysql`... (might take a while)
      ^[[A==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)
      
    • アンインストールを実施
      この時、SQL関連のファイルまでは削除しない

      $ brew uninstall mysql
      ==> Downloading https://formulae.brew.sh/api/cask.json
      ######################################################################## 100.0%
      Uninstalling /opt/homebrew/Cellar/mysql/8.0.32... (317 files, 298.2MB)
      
    • 再インストール

      $ brew install mysql
      ==> Fetching mysql
      ==> Downloading https://ghcr.io/v2/homebrew/core/mysql/manifests/8.0.32
      Already downloaded: /Users/hayashinatsuki/Library/Caches/Homebrew/downloads/86baf5da15e3e54f1fb5a1ecba7990f44cf642194348bba25fa21ff4a95f205b--mysql-8.0.32.bottle_manifest.json
      ==> Downloading https://ghcr.io/v2/homebrew/core/mysql/blobs/sha256:6cca8387c02ad0932892d792711395359df3f14ae62f7968b9ece17ff7f01d6d
      Already downloaded: /Users/hayashinatsuki/Library/Caches/Homebrew/downloads/283a047e8690979d330b5ddd4b9e09f0a77638a77ffbc90383be14b4ca028a3f--mysql--8.0.32.arm64_ventura.bottle.tar.gz
      ==> Pouring mysql--8.0.32.arm64_ventura.bottle.tar.gz
      ==> 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 -u root
      
      To start mysql now and restart at login:
        brew services start mysql
      ==> Summary
      🍺  /opt/homebrew/Cellar/mysql/8.0.32: 317 files, 298.2MB
      ==> Running `brew cleanup mysql`...
      Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
      Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
      
    • バージョン確認

      $ mysql --version
      mysql  Ver 8.0.32 for macos13.0 on arm64 (Homebrew)
      # 無事にバージョン8になっている!
      
    ⇨成功!

おわりに

HomebrewにてインストールしたMySQL Ver5.7を8.0へバージョンアップするやり方について纏めました。
バージョンアップくらい簡単にできるだろうと鷹を括っておりましたが、見事にハマりました。
ただ、おかげでHomebrewってそもそも何?、zshとbashって何?、MySQLのインストール方法は一つじゃないの?、等の付随する知識についても学べたので良い経験だったと思います(思い込みます)。

同じくHomebrewにてMySQLをバージョンアップする方の参考になれば幸いです。

まだまだ経験・知識が浅いため、誤っている箇所等ありましたらご指摘いただけますと幸いです。

参考記事

MySQLの開発環境を用意しよう(macOS)
【homebrew】MacのMySQLを5.6から8.0に更新 - Qiita
mysql 起動時のThe server quit without updating PID file エラーの回避法 - Qiita
【MySQL】Mysql ERROR! The server quit without updating PID file

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?