Centos7 mysql-5.7インストール・設定

linux

mysql-5.7をインストールしてとりあえず動くところまでの記録です

リポジトリを追加していない場合は追加しておく

# rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

mysql-5.7インストール

yum install mysql-community-server.x86_64 mysql-community-client.x86_64 mysql-community-common.x86_64

自動起動設定

# systemctl enable mysqld

自動起動が有効になっているか確認

# systemctl list-unit-files | grep mysqld

起動してみる

# /bin/systemctl start mysqld.service

仮パスワード確認

# sudo grep 'temporary password' /var/log/mysqld.log
2019-05-24T13:49:28.382826Z 1 [Note] A temporary password is generated for root@localhost: [ここにパスワードが記載されている]

設定を変更する(/etc/my.cnf)

# vi /etc/my.cnf
----最下行へ以下追加----
tmpdir=/tmp
port=3306
explicit_defaults_for_timestamp=TRUE
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
character-set-server=utf8
skip-character-set-client-handshake
default_storage_engine=InnoDB
lower_case_table_names=1
innodb_flush_method=O_DIRECT
innodb_numa_interleave=ON
log_bin=mysql-bin
server_id=1
binlog-format=ROW
expire_logs_days=14
slow_query_log=1
long_query_time=1.0
min_examined_row_limit=0
slow_query_log_file=/var/log/mysql/slow_query.log
log_timestamps=SYSTEM
sql_mode=TRADITIONAL,NO_AUTO_VALUE_ON_ZERO,ONLY_FULL_GROUP_BY

ログ用ディレクトリ作成、所有者変更

# mkdir /var/log/mysql
# chown mysql.mysql /var/log/mysql -R

rootパスワード設定

# /usr/bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: ※先ほどの仮パスワードを入力
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
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: 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 ※rootのリモートログインを拒否
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 ※testデータベース削除
 - 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 -u root -p

コメント

タイトルとURLをコピーしました