###### On Linux
1. First, stop current MySQL database server:
# /etc/init.d/mysqld stop
2. Now, start mysql server without password so that you can restart the password:
# mysqld_safe --skip-grant-tables &
3. Login without a password, enter:
# mysql -u root
4. Finally, setup a new MySQL root user password, enter::
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD('mthpw01') WHERE User='root';
mysql> GRANT ALL PRIVILEGES ON *.* to 'root'@'%' IDENTIFIED BY 'mthpw01';
mysql> FLUSH privileges;
mysql> quit
5. Replace NEW-ROOT-PASSWORD with actual password you want to use. Restart running mysql server:
# mysql -u root -p
#### กรณี On Windows
1.stop mysql ไปที่ contol panel > service >mysql กด stop
2.ไปที่ run พิมพ์ cmd >กด enter
3.พิมพ์ cd\
4.พิมพ์ cd appserv\mysql\bin กด enter
หมายเหตุ ที่เก็บ mysql จะแตกต่างกันแล้วแต่ว่าท่านเลือกใช้ web server ตัวใด
5.พิมพ์ mysqld-nt -u root --skip-grant-tables กด enter
ให้เปิดหน้าต่าง command อีกหน้าต่าง หน้าต่างเดิมไม่ต้องปิด โดย
ไปที่ run พิมพ์ cmd >กด enter
1.พิมพ์ cd\
2.พิมพ์ cd appserv\mysql\bin กด enter
หมายเหตุ ที่เก็บ mysql จะแตกต่างกันแล้วแต่ว่าท่านเลือกใช้ web server ตัวใด
3.พิมพ์ mysql กด enter
4.พิมพ์ use mysql
5.พิมพ์ UPDATE user SET Password = PASSWORD('123456') WHERE User = 'root'; กด enter
####
ปัญหาคือ ไม่สามารถเข้า database ได้ เกิด error ดังนี้
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
วิธีการแก้ปัญหาคือ
1.restart MySQL
2.ไปที่ Path ที่ลง MySQL ไว้หาไฟล์ชื่อ my.ini เปิดไฟลล์ด้วย notepad++ หาคำว่า [mysqld]
แล้วทำการ enter พิมพ์คำว่า skip-grant-tables ลงไป
3.run MySQL อีกครั้ง
4.เปิด Navicat เลือก database ชื่อ mysql ตาราง user ให้ลบ password ของ user root ออกไปให้เป็นค่าว่าง
5.stop MySQL ไปที่ Path ที่ลง MySQL ไว้หาไฟล์ชื่อ my.ini แล้วลบคำว่า skip-grant-tables ที่เราเพิ่มออกไป
6.run MySQL อีกครั้ง เสร็จเรียบร้อยครับ
ไม่มีความคิดเห็น:
แสดงความคิดเห็น