按照这篇文章在CentOS 7上安装mysql,我选择的mysql版本是5.7.17。
1.安装完成后,在此环境下,使用systemd控制mysql的启动,停止(因此没有mysql_safe脚本)。
#检查mysql状态 systemctl status mysqld #启动 systemctl start mysqld #停止 systemctl stop mysqld #设置mysql开机自启动 systemctl enable mysqld
2.重置密码的相应操作如下:
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
3.补充:按以上步骤操作时,设置参数后重启报错,检查错误日志(默认位置:/var/log/mysqld.log),发现设置--skip-grant-tables参数后,无法识别密码相关参数:validate_password_policy,validate_password_length。在配置文件/etc/my.cnf中暂时注释这两个参数后,操作成功。
本文详细介绍了如何在CentOS7上安装MySQL5.7.17,并通过systemd进行管理。同时,提供了重置MySQL管理员密码的具体步骤,包括设置临时启动选项以绕过权限验证。
603

被折叠的 条评论
为什么被折叠?



