May 25, 2011

Recovery MySQL root password

MySQL recover root password picture

tip: เปลี่น root password ตามปกติได้โดยคำสั่ง

mysqladmin -u root -pCurrentPassword password New_Password


มีข้อแม้ว่า ระหว่าง -p กับ CurrentPassword หรือ password ที่ใช้อยู่ปัจจุบัน จะต้องติดกัน ไม่มีเว้นวรรค

ถ้าหากว่าลืม password หรือ มีข้อผิดพลาดทำให้ใช้งาน root ของ mysql ไม่ได้ ก็ตำเป็นต้อง recover กันหน่อย โดยการ

1. Stop Mysql

2. Start โดยสั่งว่า mysqld_safe --skip-grant-tables &

3. mysql -u root -p แล้ว enter ผ่าน โดยไม่ต้องใส่ password

4. เรียกใช้ database mysql
mysql> use mysql;

5. Update Password
mysql> UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0


6. ออก และ Stop mysql ทีกำลังรันในโหมด skip-grant-tables

7. Start Mysql ตามปกติ

8. เรียบร้อยโรงเรียนจีน

No comments:

Post a Comment