首页 > 数据库技术 > 详细

修改Mysq数据库密码

时间:2021-06-09 21:20:37      阅读:19      评论:0      收藏:0      [点我收藏+]

一.更改root密码

1.mysqladmin直接修改
mysqladmin -uroot -p"SH123.com" password "ty123.com"
2.登陆MySQL修改相应表
mysql> desc mysql.user;
mysql> select host,user,authentication_string from mysql.user;
mysql> update mysql.user set authentication_string=password("SH123.com") where user="root" and host=‘localhost‘;

//刷新授权表

mysql> flush privileges;

二.忘记密码:

vi  /etc/my.cnf
 [mysqld]
basedir=/soft/mysql
datadir=/soft/mysql/data
skip-grant-tables   # 新增授权表

//重启MySQL数据库

systemctl restart mysqld.service

//登陆MySQL修改相应表

mysql> update mysql.user set authentication_string=password("ty123.com") where user=‘root‘ and host=‘localhost‘;
mysql> desc mysql.user;
mysql> select host,user,authentication_string from mysql.user;
mysql> update mysql.user set authentication_string=password("SH123.com") where user="root" and host=‘localhost‘;

//刷新授权表

mysql> flush privileges;

注:登陆成功后
注释skip-grant-tables 使用新的密码登陆

修改Mysq数据库密码

原文:https://www.cnblogs.com/yanghaizhen/p/14868155.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!