Hai điều đã thay đổi so với các phiên bản trước của mySQL (tôi đang sử dụng 5.7.10):
-
systemdhiện được sử dụng để chăm sóc mySQL thay vìmysqld_safe(đó là lý do tại sao tôi nhận được-bash: mysqld_safe: command not foundlỗi - nó chưa được cài đặt) -
Người dùng
usercấu trúc bảng đã thay đổi.
Vì vậy, để đặt lại mật khẩu gốc, bạn vẫn khởi động mySQL bằng --skip-grant-tables các tùy chọn và cập nhật user nhưng cách bạn thực hiện đã thay đổi.
1. Stop mysql:
systemctl stop mysqld
2. Set the mySQL environment option
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
3. Start mysql usig the options you just set
systemctl start mysqld
4. Login as root
mysql -u root
5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
-> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit
6. Stop mysql
systemctl stop mysqld
7. Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS
8. Start mysql normally:
systemctl start mysqld
Try to login using your new password:
7. mysql -u root -p
Tham khảo
Như nó nói tại https://dev.mysql.com /doc/refman/5.7/en/mysqld-safe.html ,
Điều này sẽ đưa bạn đến https:// dev .mysql.com / doc / refman / 5.7 / vi / server-management-using-systemd.html
nơi nó đề cập đến systemctl set-environment MYSQLD_OPTS= về cuối trang.
Các lệnh đặt lại mật khẩu nằm ở cuối https:// dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html