重置mysql root密码

一、 在已知MYSQL数据库的ROOT用户密码的情况下,修改密码的方法:

mysql5.7之前:
update user set password=password('tuyou@123') where user='root';
mysql5.7之后:
update user set authentication_string=password('Tuyou@123') where user='root';
set password for 'root'@'ip'=password('Tuyou@123');

二、 如查忘记了mysql数据库的ROOT用户的密码,方法如下:

vim /etc/my.cnf skip-grant-tables  
systemctl restart mysqld.service 
systemctl status mysqld.service  
mysql> update set password=password('***') where user='root';
mysql> flush privileges;

补充mysql权限知识:

授权:
grant all privileges on db.table to 'user'@'ip' identified by 'user_passwd' with grant option;
	all privileges:表示将所有权限授予给用户
	on:表示这些权限对哪些数据库和表生效,格式:数据库名.表名
	to:将权限授予哪个用户。格式:”用户名”@”登录IP或域名”
	identified by:指定用户的登录密码
	with grant option:表示允许用户将自己的权限授权给其它用户
刷新权限:flush privileges;

查看用户权限:
show grants for user
回收用户权限:
revoke create on *.* from 'user'@'ip';
flush privileges;

删除用户:
drop user 'user'@'ip';
改名:
rename user 'old_name'@'ip' to 'new_name'@'ip';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值