1
0

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 3 years have passed since last update.

M1macでMySQLインストール必勝法

Last updated at Posted at 2022-04-16

はじめに

今回は、M1macでMySQLをまだインストールしていない人も中途半端にインストールしてエラーに悩んでる人を助けられればと思い記事にしました。

コマンド
mysql -u root

上記の感じでMySQLのコマンドを走らせて、

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

これは1つのサンプルエラーですが、こんな感じのエラーを1億回ぐらい見た私でも、今回必勝法を見つけたので共有したいと思います。

ここでただサーバーを起動していないだけ問題があるかもなので、

コマンド
mysql.server start

上記を走らせて問題なくMySQLに接続ができたらこの記事とはおさらばしてもらって大丈夫です。

作戦

今回は中途半端にインストールしてエラーに悩んでる人向けに、
アンインストールしてまっさらにしてからもう一度インストールしていきます。

なのでまだインストールすらしたことのないない人は、アンインストールした後の記事から見るといいかもです。

コマンド
which mysql

これをコマンドに入力してパスがでなければ入ってない可能性があります。

またこの記事は、homebrewがインストールされている前提で進めていきます。
まだの方は、こちら。

今あるMySQLをお掃除する

コマンド
rm -rf ~/Library/PreferencePanes/My*
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
sudo rm /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
コマンド
brew uninstall mysql
コマンド
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*
sudo rm -rf /etc/my.cnf

これできれいサッパリ。

あとはインストールするだけ

コマンド
brew install mysql

一応確認する

コマンド
mysql.server start

上記のコマンドで、

Starting MySQL
. SUCCESS! 

とでれば起動の確認成功!!

コマンド
mysql -u root

下記のようになれば完了です!!!

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 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> 
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?