https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7/34207996#34207996
- systemd is now used to look after MysqL instead of MysqLd_safe (which is why you get the -bash: MysqLd_safe: command not found error - it’s not installed)
The user table structure has changed.
Set the MysqL environment option @H_404_11@ systemctl set-environment MysqLD_OPTS=”–skip-grant-tables”
Start MysqL usig the options you just set @H_404_11@ systemctl start MysqLd
Update the root user password with these MysqL commands @H_404_11@ MysqL> UPDATE MysqL.user SET authentication_string = PASSWORD(‘MyNewPassword’) @H_404_11@ -> WHERE User = ‘root’ AND Host = ‘localhost’; @H_404_11@ MysqL> FLUSH PRIVILEGES; @H_404_11@ MysqL> quit
Unset the MysqL envitroment option so it starts normally next time @H_404_11@ systemctl unset-environment MysqLD_OPTS
Try to login using your new password: @H_404_11@ MysqL -u root -p
Reference
As it says at http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html,
Note
As of MysqL 5.7.6,for MysqL installation using an RPM distribution,server startup and shutdown is managed by systemd on several Linux platforms. On these platforms,MysqLd_safe is no longer installed because it is unnecessary. For more information,see Section 2.5.10,“Managing MysqL Server with systemd”.Which takes you to http://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html where it mentions the systemctl set-environment MysqLD_OPTS= towards the bottom of the page
The password reset commands are at the bottom of @H_404_11@ http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
原文链接:https://www.f2er.com/centos/374810.html