Debian GNU/Linux Sarge にて MySQL 4.1 の root パスワードを忘れたのでパスワードを再設定。

まず、MySQL サーバを停止。
次に、パスワード無しアクセスできるようにオプションで指定して、MySQL サーバを起動 (Debian の /etc/init/mysql にオプションが渡せない? ので 本体の /usr/bin/mysqld_safe を直接起動する)。


# /etc/init.d/mysql stop
# /usr/bin/mysqld_safe --user=root --skip-grant-tables &

mysql クライアントからパスワードを変更。


# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.11-Debian_4sarge3-log
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
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> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
15 rows in set (0.00 sec)
 
mysql> select host, User, Password from user;
+-----------+------------------+------------------+
| Host      | User             | Password         |
+-----------+------------------+------------------+
| localhost | root             | 439fee19fd2e9504 |
| hogehost  | root             | 439fee19fd2e9504 |
| localhost | debian-sys-maint | 58d1a7e7d3773ffb |
| %         | hogehoge         | d249fe49531ee90f |
+-----------+------------------+------------------+
4 rows in set (0.00 sec)
 
mysql> update user set password=password('hogepassword') where user='root';
Query OK, 2 rows affected (0.05 sec)
一致数(Rows matched): 2  変更: 2  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye

MySQL サーバを再起動。


# /etc/init.d/mysql stop
# /etc/init.d/mysql start

新しいパスワードで root がログインできるか確認。


# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.11-Debian_4sarge3-log
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> exit
Bye

参考:

tags: zlashdot Database MySQL

Posted by NI-Lab. (@nilab)