- 不小心忘了mysql密碼,系統是rhel5.5 mysql版本5.0.77,yum安裝的,簡單記錄下恢復過程。
- [root@localhost ~]# /etc/init.d/mysqld stop
- Stopping MySQL: [ OK ]
- [root@localhost ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
- [root@localhost ~]# mysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1
- Server version: 5.0.77 Source distribution
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | demo |
- | mysql |
- | ndodb |
- | webdns |
- +--------------------+
- 5 rows in set (0.03 sec)
- 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 |
- | proc |
- | procs_priv |
- | tables_priv |
- | time_zone |
- | time_zone_leap_second |
- | time_zone_name |
- | time_zone_transition |
- | time_zone_transition_type |
- | user |
- +---------------------------+
- 17 rows in set (0.00 sec)
- mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
- Query OK, 3 rows affected (0.00 sec)
- Rows matched: 3 Changed: 3 Warnings: 0
- mysql> FLUSH PRIVILEGES;
- Query OK, 0 rows affected (0.00 sec)
- mysql> QUIT
- Bye
- [root@localhost ~]# /etc/init.d/mysqld restart
- Starting MySQL: [ OK ]
- [root@localhost ~]# mysql -uroot -p123456
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 10
- Server version: 5.0.77 Source distribution
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
- mysql>