LoginSignup
4
4

More than 1 year has passed since last update.

MySQLを再インストールしてやり直す場合の注意点

Posted at

実行環境

macOS Big Sur 11.4

どういうエラーが起こったか

まずはPCに入っているMySQLをアンインストールした。

% brew uninstall mysql@5.7
Uninstalling /usr/local/Cellar/mysql@5.7/5.7.35... (320 files, 234.6MB)

このあと再度MySQLをインストールした。

% brew install mysql@5.7
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
Updated 2 casks.

==> Downloading https://ghcr.io/v2/homebrew/core/mysql/5.7/manifests/5.7.35-1
Already downloaded: /Users/yamadayuuki/Library/Caches/Homebrew/downloads/8d6a41ecd64a64e4997897ce7c853b2f9c92646544b8f2df7260d72506eff4d9--mysql@5.7-5.7.35-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/5.7/blobs/sha256:983b9015ebe2bf32c43eb309de1712a289eaf22c6a17de3e5f3
Already downloaded: /Users/yamadayuuki/Library/Caches/Homebrew/downloads/d8237be5e54bf7044ca0e87a8e7d791325178341af709efbda5f54170b2efb14--mysql@5.7--5.7.35.big_sur.bottle.1.tar.gz
==> Pouring mysql@5.7--5.7.35.big_sur.bottle.1.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 -uroot

mysql@5.7 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 mysql@5.7 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"

For pkg-config to find mysql@5.7 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/mysql@5.7/lib/pkgconfig"


To restart mysql@5.7 after an upgrade:
  brew services restart mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysqld_safe --datadir=/usr/local/var/mysql
==> Summary
🍺  /usr/local/Cellar/mysql@5.7/5.7.35: 320 files, 234.6MB

さらに、ProGateのチュートリアル通りにすすめるも、エラーとなる。

% brew services start mysql@5.7
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /User/{username}/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist` exited with 5.

ただ単にbrew uninstall mysql@5.7するだけでは完全にゼロには戻らないのか、と気づいた。

解決策

(こちらのQiita記事を参考にさせていただきました。)
brew uninstall mysql@5.7の後に以下を実行しました。3つ削除しているのですが、これらは

% rm -rf /usr/local/var/mysql
% rm -rf /usr/local/etc/my.conf
% rm -rf /usr/local/etc/my.conf.default

-rfオプションは、問答無用に削除する場合に使用されます。何を削除しているのかですが、MySQLの構成ファイル(グローバルオプション)を削除しています。削除して良いのか?につてですが、これらのファイルはbrew install mysql@5.7を実行したときに作成されるので安心してください。

% cat my.cnf
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1

% cat my.cnf.default
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
4
4
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
4
4