HomebrewでMySQL設定
2023年07月14日に更新, By 管理者
- 設置可能なMySQL確認
% brew search mysql ==> Formulae automysqlbackup mysql++ mysql-client@5.7 mysql-sandbox mysql@5.6 mysqltuner mysql mysql-client mysql-connector-c++ mysql-search-replace mysql@5.7 qt-mysql
- 設置可能なバージョン確認
% brew info mysql ==> mysql: stable 8.0.31 (bottled) Open source relational database management system https://dev.mysql.com/doc/refman/8.0/en/ Conflicts with: mariadb (because mysql, mariadb, and percona install the same binaries) percona-server (because mysql, mariadb, and percona install the same binaries) Not installed From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/mysql.rb License: GPL-2.0-only with Universal-FOSS-exception-1.0 ==> Dependencies Build: cmake ✘, pkg-config ✘ Required: icu4c ✔, libevent ✘, libfido2 ✘, lz4 ✔, openssl@1.1 ✔, protobuf ✘, zlib ✘, zstd ✔ ==> 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 restart mysql after an upgrade: brew services restart mysql Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql ==> Analytics install: 62,741 (30 days), 275,550 (90 days), 1,140,321 (365 days) install-on-request: 62,624 (30 days), 274,900 (90 days), 1,137,187 (365 days) build-error: 164 (30 days)
- MySQLのインストール
% brew install mysql Running `brew update --auto-update`... ==> Auto-updated Homebrew! Updated 2 taps (homebrew/core and homebrew/services). ==> New Formulae kubent ruby@3.1 video-compare You have 3 outdated formulae installed. You can upgrade them with brew upgrade or list them with brew outdated. ==> Fetching dependencies for mysql: libevent, libcbor, libfido2, protobuf and zlib ==> Fetching libevent .. .. 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 restart mysql after an upgrade: brew services restart mysql Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
- 設置バージョン確認
% mysql --version mysql Ver 8.0.31 for macos13.0 on arm64 (Homebrew)
- MySQLサービス起動
% brew services restart mysql ==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
- MySQLサービス停止
% brew services stop mysql Stopping `mysql`... (might take a while) ==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)
- セキュリティの設定
% mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: <= enterの場合 Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
=> MySQLサービスが起動しないためエラー発生したらMySQLサービス再開始してセキュリティ設定する
・MySQL サービス開始 % brew services restart mysql ==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
% mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT 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 component? 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: 1 Please set the password for root here. New password: <= Macのパスワードと同じ Re-enter new password: Estimated strength of the password: 100 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, allowing anyone to log into MySQL without having to have 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 - Dropping test database... 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!
- 設定したパスワードを使ってMySQLにログイン
% mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.31 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>