LoginSignup
2
1

More than 5 years have passed since last update.

CentOSにMySQLを入れるメモ

Posted at

インストール

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 
2
1
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
1