一、 在已知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';