1. Tạm dừng máy chủ MySQL
sudo systemctl stop mysqld
2. Chạy MySQL ở mode skip-grant-tables
sudo mysqld_safe --skip-grant-tables &
3. Đăng nhập vào mysql với root.
mysql -uroot
4. Thay đổi mật khẩu.
use mysql;
update user set authentication_string=PASSWORD("mypassword") where User='root';
flush privileges;
quit
5. Khởi động lại máy chủ MySQL.
sudo systemctl stop mysqld
sudo systemctl start mysqld
6. Đăng nhập Mysql với mật khẩu đã đổi.
mysql -uroot -p