インストール
-
MariaDBライブラリを削除。
terminalyum remove mariadb-libs
-
yumレポジトリ追加
terminalrpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm sed -i -e "s/enabled *= *1/enabled=0/g" /etc/yum.repos.d/mysql-community.repo sed -i -e "s/enabled *= *1/enabled=0/g" /etc/yum.repos.d/mysql-community-source.repo
-
MySQLインストール
terminalyum -y install mysql-community-server --enablerepo=mysql57-community
設定&起動
-
一度サービスを起動し、rootパスワードを取得する
terminalservice mysqld start
-
/var/log/mysqld.logに書かれた初期パスワードを取得
terminalcat /var/log/mysqld.log | grep 'temporary password' | awk -F ': ' '{print $NF}'
-
フォルダ作成
terminalmkdir -p /var/log/mysqld && chown -R mysql. /var/log/mysqld mkdir -p /etc/mysql && chown -R mysql. /etc/mysql
-
cnfファイルを配置
terminalcat << \EOS > /etc/mysql/my.cnf [mysqld] # 文字コード設定 character-set-server=utf8mb4 skip-character-set-client-handshake # リンクテーブル作成を許容する symbolic-links=0 # ログ出力設定 slow_query_log=0 slow_query_log_file=/var/log/mysql/slow.log long_query_time=1 # パスワードポリシー設定 validate_password_policy=LOW # メモリサイズ拡張 max_allowed_packet=128MB # テーブル、カラム名を小文字に統一 lower_case_table_names=1 # リンクテーブル有効化 federated = 1 # InnoDB設定 innodb_buffer_pool_size = 512M #innodb_log_file_size = 256M # TIMESTAMPデフォルト値 explicit_defaults_for_timestamp = true # indexサイズ拡張対応 innodb_large_prefix=1 innodb_file_format=Barracuda innodb_file_format_max=Barracuda EOS
-
サービス再起動
terminalservice mysqld restart
-
接続確認
terminalmysql -u root -p Enter password: [初期パスワード] Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 5.7.17 MySQL Community Server (GPL) 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>
terminal# MariaDBコンソールを抜ける mysql> exit
セキュリティ設定
-
mysql_secure_installationを使う場合。
terminalmysql_secure_installation
-
同等のことを、Chef/Ansibleなどでやる場合は以下を参考に。。。
この方法、5.7ではデフォルトパスワードではインタラクティブに
パスワードを受け付けてもらえず、使えないみたいだ。terminalmysql -u root -p << \EOS /* rootユーザー作成 & パスワード設定 */ GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '[password]' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '[password]' WITH GRANT OPTION; /* anonymasユーザー削除 */ DELETE FROM mysql.user WHERE User = ''; /* testデータベース削除 */ DROP DATABASE IF EXISTS test; /* 権限反映 */ FLUSH PRIVILEGES; EOS
完了
- 以上