LoginSignup
2
5

More than 5 years have passed since last update.

centos7に導入したMySQL5.6の初期設定と動作確認

Last updated at Posted at 2017-05-15

MySQL5.6をmac上のvagrantとvirtualboxで構築したcentos7の上に導入した後の初期設定です。
ただ、この設定については仮想環境かどうかには関係していないのでMySQL5.6の汎用的な設定作業になります。

セキュリティ設定

インストール後に利用できるセキュリティの初期設定用のユーティリティを利用します。(mysql_secure_installation)このコマンドで対話的に答えていくだけで最低限の設定ができます。

[vagrant@localhost ~]$ sudo mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): ← 初期パスワードは設定されていないので、このままenterします。
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y   ←rootユーザーのパスワードを設定します。
New password: ← パスワードを入力します。 
Re-enter new password: ←再度パスワードを設定します。
Password updated successfully!
Reloading privilege tables..
 ... Success!


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? [Y/n] Y ←anonymousユーザーを削除します。
 ... 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? [Y/n] 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? [Y/n] n ←最初から用意されているテスト用のデータベースを削除するかどうかを聞かれています。後で動作確認してみるのでこのまま残しておきます。
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y ←再起動をしたら反映されますが、今すぐに反映させるためにYを選びます。
 ... Success!

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

完了しました。

my.cnfの編集

/etc/my.cfgファイルをエディタで開いて編集します。

sudo vi /etc/my.cnf

以下のように追加します。

/etc/my.cnf
[mysqld] のセクションに下記行を追加する
character-set-server=utf8

[mysql]のセクションを追加して下記行を追加する
default-character-set=utf8

サーバーを再起動します。

sudo systemctl stop mysqld.service
sudo systemctl start mysqld.service

MySQLへの接続と動作確認

設定の終わったMySQLへ接続してみます。rootユーザーで接続し、先程設定したパスワードを利用します。

[vagrant@localhost etc]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

mysql> quit;
Bye

無事稼働しました。

参考

macOS Sierra バージョン10.12.4
Vagrant 1.9.4
VirtualBox 5.1.22
CentOS 7.0 64bit
MySQL 5.6.36


シリーズ一覧 (vagrant centos LAMP環境構築)

1.macにvagrantでcentos7の仮想環境を構築したときの初期設定
2.mac上の仮想環境に構築したcentos7にPHPを導入する
3.mac上の仮想環境に構築したcentos7でPHPのビルトインサーバーを利用する
4.mac上の仮想環境に構築したcentos7にapahceを導入する
5.mac上の仮想環境に構築したcentos7にmysqlを導入する
6.centos7に導入したMySQL5.6の初期設定と動作確認

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5