いやー忘れんな!という突っ込みはあろうが、個人サーバで設定したMySQLのrootパスワードを忘れるなんてことはよくある話。
CentOSでの設定例だが、/etc/my.cnfファイルを編集して再起動するとパスワードの再設定が可能となる。
該当ファイルのに先頭に[mysqld]セクションがあるはず、その直下あたり以下のようにskip-grant-tablesを入れて、mysqlを再起動する。
[mysqld]
#この行を入れる
skip-grant-tables
その後はmysqlにパスワードなしでログインできるので
[root@rutake]# mysql -u root mysql
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 2 to server version: 4.1.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> UPDATE user SET Password=PASSWORD('tmp') WHERE User='root';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> exit
Bye
あとは先ほど追加した記述をコメントアウトして再起動すればOK!
mysqldにオプションでつけてもいいらしいけど、設定ファイルいじるほうが簡単だと思って紹介した。