[root@ufuso ~]# mysql_secure_installation ← MySQL初期設定
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] ← ENTERキーを押す
New password: ← rootパスワードを設定してENTERキーを押す
Re-enter new password: ← rootパスワードを再度入力してENTERキーを押す
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] ←匿名ユーザー削除のためENTERキーを押す
... 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] ←リモートからのrootログイン禁止のためENTERキーを押す
... 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] ←testデータベース削除のためENTERキーを押す
- 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? [Y/n] ←table再読込みのためENTERキーを押す
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@ufuso ~]# mysql -u root -p ← MySQLへrootでログイン
Enter password: ← rootパスワードの入力
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 10
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, 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>select user,host,password from mysql.user; ← 登録済ユーザ、パスワード確認
+------+----------------------+----------+
| user | host | password |
+------+----------------------+----------+
| root | localhost | | ← パスワードが設定されていない
| root | ufuso.dip.jp | | ← パスワードが設定されていない
| root | 127.0.0.1 | | ← パスワードが設定されていない
+------+----------------------+----------+
3 rows in set (0.00 sec)
mysql> set password for root@localhost=password('rootパスワード');
← ホスト名がlocalhostのrootユーザにパスワード設定
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@'ufuso.dip.jp'=password('rootパスワード');
← ホスト名が自ホストのrootユーザにパスワード設定
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@127.0.0.1=password('rootパスワード');
← ホスト名が127.0.0.1のrootユーザにパスワード設定
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user; ← 登録済ユーザ、パスワード確認
+------+----------------------+------------------+
| user | host | password |
+------+----------------------+------------------+
| root | localhost | **************** | ← パスワードが設定された
| root | ufuso.dip.jp | **************** | ← パスワードが設定された
| root | 127.0.0.1 | **************** | ← パスワードが設定された
+------+----------------------+------------------+
3 rows in set (0.00 sec)
mysql> exit ← MySQLサーバーからログアウト
Bye
[root@ufuso ~]# mysql -u root -h localhost
← ホスト名がlocalhostのrootユーザでパスワードなしでログインできないことを確認
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@ufuso ~]# mysql -u root -h 'ufuso.dip.jp'
← ホスト名が自ホストのrootユーザでパスワードなしでログインできないことを確認
ERROR 1045 (28000): Access denied for user 'root'@'ufuso.dip.jp' (using password: NO)
[root@ufuso ~]# mysql -u root -h 127.0.0.1
← ホスト名が127.0.0.1のrootユーザでパスワードなしでログインできないことを確認
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@ufuso ~]# mysql -u root -h localhost -p ← MySQLへrootでログイン
Enter password: ← MySQLのrootパスワード応答
ホスト名がlocalhostのrootユーザでパスワードありでMySQLサーバーへログインできることを確認
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 18 to server version: 4.1.12
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> exit ← MySQLサーバーからログアウト
Bye
[root@ufuso ~]# mysql -u root -h 'ufuso.dip.jp' -p
Enter password: ← MySQLのrootパスワード応答
ホスト名が自ホストのrootユーザでパスワードありでMySQLサーバーへログインできることを確認
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 19 to server version: 4.1.12
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> exit ← MySQLサーバーからログアウト
Bye
[root@ufuso ~]# mysql -u root -h 127.0.0.1 -p ← MySQLへrootでログイン
Enter password: ← MySQLのrootパスワード応答
ホスト名が127.0.0.1のrootユーザでパスワードありでMySQLサーバーへログインできることを確認
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 18 to server version: 4.1.12
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> exit ← MySQLサーバーからログアウト
Bye
※ホスト名を指定してログインできない場合の対処
ホスト名を指定してログインできない原因は、サーバーが自身のホスト名を名前解決
(ホスト名→IPアドレス)できないことが原因。サーバーが自身のホスト名を名前解決
できるように、サーバーの/etc/hostsにホスト名とIPアドレスの対応を追加する。
[root@ufuso ~]# grep `hostname` /etc/hosts ← /etc/hostsにホスト名が定義してあるか確認
なにも表示されない=ホスト名が定義されていないことを確認
[root@ufuso ~]# echo 127.0.0.1 `hostname` >> /etc/hosts
← /etc/hostsにホスト名の定義を追加
[root@ufuso ~]# grep `hostname` /etc/hosts ← /etc/hostsにホスト名が定義してあるか確認
127.0.0.1 ufuso.dip.jp ← ホスト名定義追加を確認
[root@ufuso ~]# mysql -u root -p ← MySQLへrootでログイン
Enter password: ← MySQLのrootパスワード応答
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 7 to server version: 4.1.12
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> show databases; ← 登録データベース確認
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
mysql> exit ← ログアウト
Bye
|