CentOS 7 MySql 5.7密码重置问题

按照这篇文章在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中暂时注释这两个参数后,操作成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值