工作记录-mysql数据库修改root密码(root密码忘记)
记录:mysql数据库部署在centos服务器上,忘记密码,操作mysql修改root密码。
1.通过xshell工具远程连接服务器
2.操作mysql数据库
1)编辑配置文件 (关闭认证权限)
vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
2)重启mysql
systemctl restart mysqld
3)登录mysql(不需要密码登录)
mysql -u root
4)更新user表格得密码(这里用alter语句不行,因为关了权限认证)
user mysql;(使用user库)
update user set authentication_string=password(‘你的密码’) where user=‘root’;(修改user表的root密码,这个支持5.7或5.8版本)
update user set password=password(‘你的密码’) where user=‘root’;(支持5.6版本)
5)赋权保存
flush privileges;
6)重启mysql服务(为了安全,可以删除my.cnf新增那句话)
systemtcl restart mysqld
7)登录mysql
msyql -u root -p
输入你的密码就可以了