Skip to content

Instantly share code, notes, and snippets.

@oppara
Created January 20, 2020 10:37
Show Gist options
  • Save oppara/69661331f701c7642f8df55634eae93b to your computer and use it in GitHub Desktop.
Save oppara/69661331f701c7642f8df55634eae93b to your computer and use it in GitHub Desktop.
Amazon Linux に MySQL をインストールする

mariaDB のアンインストール
# yum -y remove mariadb-libs

MySQL のリポジトリを追加
# yum -y install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

インストール
# yum install mysql-community-server

バージョン確認
# mysql --version
mysql  Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using  EditLine wrapper
# mysqld -V
mysqld  Ver 5.7.29 for Linux on x86_64 (MySQL Community Server (GPL))

起動
# systemctl start mysqld.service

自動起動設定
# systemctl enable mysqld.service

パスワード確認
# cat /var/log/mysqld.log | grep password

上記で確認したパスワードでログインして、パスワードを変更
# mysql -u root -p
mysql> ALTER USER root@localhost IDENTIFIED BY '新しいパスワード';

文字コード設定
# cp -p  /etc/my.cnf /etc/my.cnf.20200120
# vim /etc/my.cnf

再起動して文字コードの確認
# systemctl restart mysqld
# mysql -u root -p -e 'show variables like "chara%";'
Enter password: 
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

タイムゾーン設定
# /usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo > ~/timezone.sql
# mysql -u root -p -Dmysql < ~/timezone.sql
# vim /etc/my.cnf

再起動してタイムゾーンの確認
# systemctl restart mysqld
# mysql -u root -p -e 'show variables like "%time_zone%";'
Enter password: 
+------------------+------------+
| Variable_name    | Value      |
+------------------+------------+
| system_time_zone | JST        |
| time_zone        | Asia/Tokyo |
+------------------+------------+


セキュリティ設定
# mysql_secure_installation -p -D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment