Mysqlをローカルに入れてみる(Mac)
Mysqlインストール
前回の記事でGoのwebフレームワークを使ってAPIを実装するにあたりローカルにMysqlを用意してMVCを実装してみる。
以下コマンドでインストール
$ brew install mysql
mysqlのバージョンを確認する
$ brew info mysql mysql: stable 5.7.14 (bottled) Open source relational database management system https://dev.mysql.com/doc/refman/5.7/en/ Conflicts with: mariadb, mariadb-connector-c, mysql-cluster, mysql-connector-c, percona-server /usr/local/Cellar/mysql/5.7.14 (13,467 files, 447M) * Poured from bottle on 2016-09-02 at 00:12:25
サーバーを開始してみる
$ mysql.server start Starting MySQL . SUCCESS!
mysqlにログインしてみる
$ mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.7.14 Homebrew Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 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>
こんな感じでログインできたことがわかります。
次にパスワードを設定してみる
Mysqlでのパスワード設定
ここで少しつまづく
$ mysql_secure_installation
ここでpaswordの強度を聞かれる - Low - Medium - Strong
何も確認せずとりあえずMediumを使って半角英数字小文字と数字で設定すると 以下エラーが出る
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
MySQL 5.7.8以降のrpmパッケージではvalidate_passwordプラグインがデフォルトで有効になっているらしい
mysql> SHOW VARIABLES LIKE 'validate_password%'; +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +--------------------------------------+--------+
どうやら特殊文字と半角大文字が一文字ずつ必要だったらしい
今回はローカルでしか使わないのでセキュリティレベルを落としてパスワード作成
mysql> SET GLOBAL validate_password_policy=LOW; Query OK, 0 rows affected (0.00 sec)
そしてもう一度以下コマンドで設定していくとパスワードを設定することができます。
$ mysql_secure_installation
ログインしてみる
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.7.14 Homebrew Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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>
無事ログインできました。
おまけ(mysqlセキュリティポリシー)
LOW ポリシーは、パスワードの長さのみテストします。パスワードは少なくとも 8 文字の長さでなければなりません。
MEDIUM ポリシーは、パスワードが最低 1 つの数値文字を含み、1 つの小文字および大文字を含み、1 つの特殊文字 (英数字以外) を含む必要があるという条件を追加します。
STRONG ポリシーは、パスワードの 4 文字以上の部分文字列が、(辞書ファイルが指定された場合に) 辞書ファイル内の単語と一致してはならないという条件を追加します。