前提
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
MySQLの設定変更
/etc/my.cnf
にskip-grant-tables
を追加(パスワードなしでログインする)
# vi /etc/my.cnf
// ADD EOF "skip-grant-tables"
MySQLを使っているサービスを停止させる
MySQLを再起動
# systemctl restart mysqld
rootユーザのパスワード変更
# mysql -u root
mysql> use mysql
・・・
Database changed
mysql> UPDATE user SET authentication_string=password('新規パスワード') WHERE user='root';
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql> quit
MySQLを再起動
/etc/my.cnf
からskip-grant-tables
を削除(パスワードなしでログインする)
# vi /etc/my.cnf
// DELETE EOF "skip-grant-tables"
MySQLを使っているサービスを停止させる
MySQLを再起動
# systemctl restart mysqld