Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
mysql实现添加用户并授权_创想鸟

mysql实现添加用户并授权

mysql实现添加用户并授权

查询所有用户

方式1:

mysql> select host, user, password from mysql.user;               -- 5.7版本之前的mysql> select host, user, authentication_string from mysql.user;  -- 5.7版本之后的,包括5.7

方式2:

mysql> select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;

查询用户权限

all表示所有权限

select表示只查权限

update表示只改权限

delete表示只删权限等。

(在线学习视频教程推荐:mysql视频教程)

方式1:

mysql> show grants for "user"@"host";mysql> show grants for "root"@"localhost";

方式2:

mysql> select * from mysql.user where user='root'G;

添加授权用户(新创建的用户,默认情况下是没有任何权限的):使用root用户登录数据库

命令格式如下:

度加剪辑 度加剪辑

度加剪辑(原度咔剪辑),百度旗下AI创作工具

度加剪辑 63 查看详情 度加剪辑

mysql> create user "用户名"@"IP地址" identified by "密码";
mysql> create user "haidon" identified by "123456";       -- 此时密码为123456,host值为%。mysql> create user "haidon"@"%" identified by "123456";   -- 此时密码为123456

分配用户权限(给用户授权)

命令格式如下:

mysql> grant 权限类型 on 数据库名.表名 to '用户名'@'ip地址' identified by '用户密码' with grant option;

常用的权限类型有以下几种:

all privileges:所有权限。
select:读取权限。
create:创建权限。
delete:删除权限。
update:更新权限。
drop:删除数据库、数据表权限。

允许访问所有数据库下的所有表

mysql> grant all privileges on *.* to '用户名'@'指定ip' identified by '用户密码' ;

允许访问指定数据库下的所有表

mysql> grant all privileges on test.* to '用户名'@'指定ip' identified by '用户密码' ;

允许访问指定数据库下的指定表

mysql> grant all privileges on test.test to '用户名'@'指定ip' identified by '用户密码' ; mysql> grant all privileges on tornado.* to 'haidon'@'%' identified by '123456';

收回用户权限(使用root用户操作)

mysql> revoke select on tornado.* from "haidon"@"%";mysql> revoke all on tornado.* from "haidon"@"%";

删除授权用户

mysql> drop user "haidon"@"%";                      -- 删除方法1mysql> delete from mysql.user where user="haidon";  -- 删除方法2

刷新权限

mysql> flush privileges;

相关文章教程推荐:mysql教程

以上就是mysql实现添加用户并授权的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/365997.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Bing浏览器国际服中文界面版-Bing国际版浏览器全球服务器访问入口
上一篇 2025年11月6日 05:16:57
荣耀X50Pro怎么设置HD高清摄像?
下一篇 2025年11月6日 05:17:11

相关推荐

发表回复

登录后才能评论
关注微信