MySQLのパスワードを忘れたら
■概要
実際にパスワードを忘れたことはないが、MySQLをアップグレードするたびにrootパスワードが通らなくなるので、その対策。
|
■MySQLの停止
[root@ufuso ~]# killall mysqld ← mysqlを停止させる
[root@ufuso ~]# /usr/bin/mysqld_safe –user=root –skip-grant-tables & mysql mysql
[1] 22417
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) ← mysqlをパスワードなしで起動させるが繋がらない。パスに間違いは無し・・・?
[root@ufuso ~]# /usr/local/mysql/bin/safe_mysqld –user=root –skip-grant-tables & mysql mysql ← サイトで対処法を確認してもう一度mysqlをパスワードなしで起動させる・・・繋がった。そんなとこにMySQLはないんだけど
[2] 22528
-bash: /usr/local/mysql/bin/safe_mysqld: そのようなファイルやディレクトリはありません
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.42 MySQL Community Server (GPL) by Remi
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> update user set Password=null where Host=’localhost’ and User=’root’; ← rootのパスワードを削除する
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> exit ← MySQLを終了させる
Bye
[2]+ Exit 127 /usr/local/mysql/bin/safe_mysqld –user=root –skip-grant-tables
[root@ufuso ~]# /etc/rc.d/init.d/mysqld restart ← 設定を反映させるためにMySQLを再起動
100127 00:53:11 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
MySQL を停止中: [ OK ]
MySQL を起動中: [ OK ]
[1]+ Done /usr/bin/mysqld_safe –user=root –skip-grant-tables
[root@ufuso ~]# mysql -u root ← パスワードなしでrootが入れることを確認
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.42 MySQL Community Server (GPL) by Remi
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> set password for root@localhost=password(‘xxxxxxxxxx’); ← rootのパスワードを再設定する
Query OK, 0 rows affected (0.00 sec)
mysql> exit ← 終了する
Bye
[root@ufuso ~]# mysql -u root -p ← rootの新パスワードでログインできることを確認する
Enter password: ← rootの新パスワードを入力する
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.42 MySQL Community Server (GPL) by Remi
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> quit ← 確認できたので終了する
Bye
|
|
>>>お役に立ちましたらクリックをお願いいたします。励みになります。
にほんブログ村

← 戦闘モード維持のため、参考になりましたらクリックをお願いします。
にほんブログ村
1月 31st, 2010 in
CentOS5.4 x86_64