MySQLでrootログインできないとき
MySQLでrootユーザーの登録、権限の設定ができていないと、ログインできない。
# mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
対処法としては、MySQLサーバを停止して、--skip-grant-tablesをつけて起動する。
# service mysqld stop # mysqld_safe --skip-grant-tables &
このあと mysql -u root でログインできるけど、うまくいかないときもあって、
131007 04:20:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 131007 04:20:14 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
という感じでMySQLが起動できない。
原因は、/etc/my.cnfの設定を変えていたからで、とりあえずデフォルトに戻したらログインできた。
/etc/my.cnf
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
ログインできたらrootの権限を設定する。
ここのブログを参考に。