【MySQL5.6】root初期パスワードメモ(error: 'Access denied for user 'root'@'localhost' (using password: NO)')
MySQLの初期設定について
Rails環境構築中にMySQLの初期設定でハマったので、メモです。
下記のエラーはrootユーザの権限設定ができていないとき、もしくは入力したパスワードが間違っているときのエラー
$ sudo /usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'
下記で権限付与とパスワード設定を試みたがエラー
※エラーはmysqlのバージョンアップをした際に発生するエラー
⇒新規でインストールしているので、対象外
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> select * from user; Empty set (0.00 sec) mysql> truncate table user; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on *.* to root@localhost identified by 'password' with grant option; ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 43, found 42. Created with MySQL 50537, now running 50640. Please use mysql_upgrade to fix this error.
◎初期パスワードが記載されている場所は2箇所
※バージョンによっては空欄の場合もあるらしいので、パスワード変更時の旧パスワードは何も入力せずEnter
MySQL 5.6
$ /root/.mysql_secret
MySQL 5.7
$ cat /var/log/mysqld.log | grep 'temporary password'
$ cat /var/log/mysqld.log | grep 'password is generated'
【インストール手順】
◎mysqlインストール(5.7)※CentOS7系
https://enomotodev.hatenablog.com/entry/2016/09/01/225200
http://www.kakiro-web.com/linux/mysql-install.html
$ sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
$ sudo yum install mysql-community-server
◎mysqlインストール※CentOS6系
https://qiita.com/zakki/items/f065c79bbe287481c292
$ sudo yum install http://dev.mysql.com/get/mysql-community-release-el6- 5.noarch.rpm
$ sudo yum install mysql-community-server
【環境情報】
CentOS release 6.9 (Final)
mysql Ver 14.14 Distrib 5.6.40, for Linux (x86_64) using EditLine wrapper
【参考サイト】
◎MySQL設定
https://qiita.com/ksugawara61/items/336ffab798e05cae4afc
https://qiita.com/Esfahan/items/83200c64de8d826677b5
http://www.aiship.jp/knowhow/archives/28257
http://www.goofoo.jp/2011/11/1457
◎root直下のパスワード記載ファイル
http://taka-say.hateblo.jp/entry/2014/05/15/111906
https://yoku0825.blogspot.com/2012/11/mysql568rpm.html
http://www.hack-log.net/entry/2015/10/26/100000
http://pcl.solima.net/archives/387
https://qiita.com/shrimpx/items/b52eb677ea1ed4660bdb
◎rootパスワード設定(mysqladmin)
https://dev.mysql.com/doc/refman/5.6/ja/mysqladmin.html
https://weblabo.oscasierra.net/mysql-56-init-setup/
【その他】
◎プロセス確認
$ rpm -qa | grep mysql
◎バージョン確認
$ mysql --version
◎アンインストール
$ sudo yum remove mysql*