Bước 1 : Stop MySQL Service - dừng dịch vụ

sudo service mysql stop


Bước 2 : Kill all running mysqld - chắc chắn là tắt triệt để dịch vụ

sudo killall -9 mysqld


Bước 3 : Starting mysqld in Safe mode - khởi động mysql ở chế độ Safe

sudo mysqld_safe --skip-grant-tables --skip-networking &


Bước 4 : Start mysql client - khởi động mysql đăng nhập với user root, lúc này sẽ không yêu cầu password

mysql -u root


Bước 5: After successful login, please execute this command to change any password - sau khi login thành công, chạy lệnh sau để mysql thay đổi password

FLUSH PRIVILEGES;


Bước 6: You can update mysql root password - tạo password mới cho người dùng root

UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';

Chú ý : for mysql > 5.7 use this instead of above - nếu máy bạn chạy mysql phiên bản > 5.7 thực thi lệnh dưới đây

UPDATE mysql.user SET authentication_string=PASSWORD('newpwd') WHERE User='root';


Bước 7: Update mysql changed - Cập nhật thay đổi bằng lệnh dưới đây

FLUSH PRIVILEGES;


Bước 8: Exit mysql console - Thoát mysql

exit


Bước 9: Kill mysqld_safe and restart mysql service - Tắt mysqld_safe và khởi động lại mysql

sudo killall mysqld_safe && sudo service mysql start

Tận hưởng thành quả ! Enjoy !