My開発メモ

macにMySQL5.7をインストールする(macOS/Monterey)

すでに MySQL8 をインストールしてしまったので、 これは 実際におこなったわけではない。
しかし、必要になるときがあるかもしれないので、書いておく。
このサイトに書かれてある手順をまとめただけである。

MySQL5.7をHomebrewでmacOSにインストールする手順

% brew update
% brew install mysql@5.7

これでインストールはできている。

パスを通す

インストール時のメッセージに以下の内容が出力されるということである。

If you need to have mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

であるから、そのように行う。

% echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zprofile

反映させる。

% source ~/.zprofile

確認

% mysql --version

MySQL5.7 の起動

% brew services start mysql@5.7

もし、ここで、以下のようなエラーが出るかもしれない。

Error: Permission denied @ rb_sysopen - /Users/seiichinukayama/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist

この場合は、以下のような状況だと思われる。

% ls -l /Users/seiichinukayama/Library | grep LaunchAgents
drwxr-xr-x 8 root staff 256 6 28 LaunchAgents

この所有権を変更する。

% sudo chown seiichinukayama /Users/seiichinukayama/Library/LaunchAgents

これで brew services start mysql@5.7 ができるようになる。

パスワードなしで rootログインできる

% mysql -uroot

セキュリティの設定

rootのパスワードの変更ができる。
開発環境であれば必要ないかもしれない。

% mysql_secure_installation

途中、VALIDATE PASSWORD というのは、ユーザーのパスワード設定に一定の制限を かけるもので、その制限レベルを3段階から選択できる。 必要なければ、「n」でインストールしないこともできるのかな。

以下の記述は、 MySQL5.7をHomebrewでmacOSにインストールする手順 に書かれていたものである。

Securing the MySQL server deployment.

Enter password for user root: 初期パスワードを入力する

The existing password for the user account root has expired. Please set a new password.

New password: 新しいパスワードを入力する

Re-enter new password: 再度同じ新しいパスワードを入力する

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: ポリシーに沿った新しいパスワードを入力

Re-enter new password: 再度新しいパスワードを入力する

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user, a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

参考

カテゴリー: MacOS, memo

タグ: mysql, MySQL5.7

カウント: 187