微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MySQL修改用户密码

目录

MysqL5.7.17

1.1、普通用户的管理

(1)使用create user语句创建普通用户

create user的基本语法格式为:

create user user[identified by 'password';]

说明:

a、user 的格式为:’user_name'@'host name'。

b、localhost表示本地主机;

c、identified by 指定用户密码,注意用户名和密码大小写;

d、可以同时创建多个user,中间使用 隔开

例:

MysqL>create user 
     >'user01'@'localhost' identified by 'xxxx',
     >'user02'@'localhost' identified by 'xxxx';

创建成功后,可以通过 select user from user; 来进行查看用户是否创建成功

1.2、使用grant语句创建用户

语法:

grant priv_type on database.table to user [identified by 'password'] [with grant option]

例:

grant select,delete on *.* to 'user'@'localhost' identified by 'xxxxx' with grant option;

1.3、删除普通用户

(1)使用drop user删除用户

语法:drop user user_name;

drop user kylin@localhost;

        drop user语句删除用户的时候不会去关闭这个用户正在使用的会话,但是当这个用户关闭了会话再次进行登录的时候就会失败。drop user语句执行者需要具有MysqL的全局create user权限和delete权限。

(2)使用delete语句删除用户。delete基本语法格式为:

       delete from user where host = 'hostname' and user = 'username';

       如果删除用户数据库中创建了数据表、索引或数据库对象,这些信息继续存在。

1.4、修改用户名

        可以使用 rename user语句来实现。如果旧账户不存再或者新账户已存在,则会出现错误

基本语法:

rename user old_user to new_user;

支持同时修改多个用户名称

MysqL>rename user 
     >'demo01'@'localhost' to 'test01'@'localhost',
     >'demo02'@'localhost' to 'test02'@'localhost';  

1.5、修改用户密码

修改某个用户登录密码,可以使用MysqLadmin、update或set password语句。

(1)root用户修改密码

① 使用MysqLadmin命令。MysqLadmin命令的基本语法格式为:

MysqLadmin -u user -h localhost -p pasword 'newpassword';

② 使用update修改用户 root 的密码

update MysqL.user set password = password('newPassword') where user = 'root' and host = 'localhost';

(2)使用set语句修改用户密码,其语法格式为:

set password [for user] = password('newPassword');

set password for 'test01'@localhost = password('newPassword');

注:在MysqL8.0以上版本,

 update MysqL.user set password='newpassword' where user='root';

 

 update MysqL.user set password=PASSWORD('newpassword') where User='root'; 这两条命令已经不起作用了。

MysqL8.0版本

        在进行修改用户密码的使用,由于MysqL8.0版本在user表中取消了password字段authentication_string:字段表示用户密码,而authentication_string字段下只能是MysqL加密后的41位字符串密码。

alter user 'username'@'hostname' identified by 'password'; --- 修改用户username的密码为password

flush privileges;   -- 刷新权限


原文地址:https://www.jb51.cc/wenti/3288156.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐