MySQLのインストール(Mac)

MySQL

インストールできるバージョンを確認する

% brew search mysql
==> Formulae
automysqlbackup                mysql++                        mysql-client@5.7               mysql-client@8.4               mysql-search-replace           mysql@8.0                      mysqltuner
mysql                          mysql-client                   mysql-client@8.0               mysql-connector-c++            mysql@5.7                      mysql@8.4                      qt-mysql

==> Casks
mysql-connector-python                     mysql-shell                                mysqlworkbench                             navicat-for-mysql                          sqlpro-for-mysql

今回は mysql@8.0 をインストールする

インストール

% brew install mysql@8.0
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:e7340e4a1d7cc0f113686e461b93114270848cb14676e9037a1a2ff3b1a0ff32
  :
==> Caveats
==> mysql@8.0
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

mysql@8.0 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.

If you need to have mysql@8.0 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc

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

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

To start mysql@8.0 now and restart at login:
  brew services start mysql@8.0
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/mysql@8.0/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql

最後に、色々設定してね、と出るがとりあえずこのままで

バージョン確認

% mysql --version
mysql  Ver 8.0.39 for macos14.4 on arm64 (Homebrew)

起動

% brew services start mysql@8.0
==> Tapping homebrew/services
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 3343, done.
remote: Counting objects: 100% (489/489), done.
remote: Compressing objects: 100% (166/166), done.
remote: Total 3343 (delta 382), reused 328 (delta 322), pack-reused 2854 (from 1)
Receiving objects: 100% (3343/3343), 965.29 KiB | 17.55 MiB/s, done.
Resolving deltas: 100% (1622/1622), done.
Tapped 2 commands (48 files, 1.1MB).
==> Successfully started `mysql@8.0` (label: homebrew.mxcl.mysql@8.0)

ログイン

パスワードを求められるが、デフォルト空なのでそのまま return を押せば良い

% 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.39 Homebrew

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

exit で抜けられる

mysql> exit
Bye

停止

% brew services stop mysql@8.0
Stopping `mysql@8.0`... (might take a while)
==> Successfully stopped `mysql@8.0` (label: homebrew.mxcl.mysql@8.0)

コメント

タイトルとURLをコピーしました