Help us understand the problem. What is going on with this article?

CentOSにMySQLを入れるメモ

More than 5 years have passed since last update.

インストール

yumを使ってインストールする。

$ sudo yum --enablerepo=remi install mysql mysql-server

起動

もろもろ設定は必要だけど、吹っ飛ばしてとりあえず起動する。

$ sudo /etc/init.d/mysqld start 

再起動後も自動で起動する様にする

$ chkconfig --list mysqld 
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
hnsta:~$ sudo chkconfig mysqld on
hnsta:~$ chkconfig --list mysqld 
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

rootパスワード変更

パスワードなしは無いので変更する。

$ mysql -u root
mysql> set password for root@localhost=password('*****');

不要なユーザの削除

引き続きMySQLでの作業。

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | hnsta.com |
| root | hnsta.com |
|      | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 sec)

mysql> DELETE FROM mysql.user WHERE user = '' OR ( user = 'root' AND host != 'localhost' );
Query OK, 5 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)

不要なデータベースの削除

testはいらないので削除する。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

.mysql_historyの削除

.mysql_historyの削除をしないと平文のパスワードが残ってしまうので削除する。

$ rm ~/.mysql_history 
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away