MySql的用户管理权限

登陆连接

1.127.0.0.1/其他远程数据库

mysql -u admin -p -h 127.0.0.1 -P 3306 -D t_user 

注:-u 代表用户,-p代表密码 ,-h代表host, -P代表端口,-D代表数据库

2.本地localhost

msyql -u admin  -p

新建用户
CREATE USER test@127.0.0.1 IDENTIFIED by 'admin123';

修改用户名和连接地址
RENAME USER test@127.0.0.1 to n_test@127.0.0.1;

修改用户密码
SET PASSWORD FOR test@127.0.0.1 ='admin';

删除用户
DROP USER n_test@127.0.0.1;

刷新服务,马上生效
FLUSH PRIVILEGES;

展示目前数据库所有的权限种类
SHOW PRIVILEGES;

展示当前用户拥有的权限
方法一

SHOW GRANTS FOR test@127.0.0.1;
方法二
SELECT * FROM USER where USER='test';

赋予权限
GRANT SELECT,INSERT,UPDATE on testdb.t_user to n_test@127.0.0.1;

收回权限
REVOKE INSERT,UPDATE on testdb.t_user FROM n_test@127.0.0.1;

上面的命令也可使用多个权限同时赋予和回收,权限之间使用逗号分隔

grant select,update,delete  ,insert  on dmc_db.*  to  zx_root;

如果想立即看到结果使用

flush  privileges ;

grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。

grant select on testdb.* to common_user@’%’

grant insert on testdb.* to common_user@’%’

grant update on testdb.* to common_user@’%’

grant delete on testdb.* to common_user@’%’

或者,用一条 MySQL 命令来替代

grant select, insert, update, delete on testdb.* to common_user@’%’

grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。

grant 创建、修改、删除 MySQL 数据表结构权限。

grant create on testdb.* to developer@’192.168.0.%’;

grant alter on testdb.* to developer@’192.168.0.%’;

grant drop on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 外键权限。

grant references on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 临时表权限。

grant create temporary tables on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 索引权限

grant index on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 视图、查看视图源代码 权限。

grant create view on testdb.* to developer@’192.168.0.%’;

grant show view on testdb.* to developer@’192.168.0.%’;

grant 操作 MySQL 存储过程、函数 权限。

grant create routine on testdb.* to developer@’192.168.0.%’; -- now, can show procedure status

grant alter routine on testdb.* to developer@’192.168.0.%’; -- now, you can drop a procedure

grant execute on testdb.* to developer@’192.168.0.%’;

grant 普通 DBA 管理某个 MySQL 数据库的权限。

grant all privileges on testdb to dba@’localhost’

其中,关键字 “privileges” 可以省略。

grant 高级 DBA 管理 MySQL 中所有数据库的权限。

grant all on *.* to dba@’localhost’

MySQL grant 权限,分别可以作用在多个层次上。

1. grant 作用在整个 MySQL 服务器上:

grant select on *.* to dba@localhost; -- dba 可以查询 MySQL 中所有数据库中的表。

grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库

2. grant 作用在单个数据库上:

grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在存储过程、函数上:

grant execute on procedure testdb.pr_add to ’dba’@’localhost’

grant execute on function testdb.fn_add to ’dba’@’localhost’

 

说明一:设置权限时必须给出一下信息

1,要授予的权限

2,被授予访问权限的数据库或表

3,用户名

说明二:grant和revoke可以在几个层次上控制访问权限

1,整个服务器,使用 grant ALL  和revoke  ALL

2,整个数据库,使用on  database.*

3,特点表,使用on  database.table

4,特定的列

5,特定的存储过程

说明三:user表中host列的值的意义

1,%              匹配所有主机

2,localhost    localhost不会被解析成IP地址,直接通过UNIXsocket连接

3,127.0.0.1      会通过TCP/IP协议连接,并且只能在本机访问;

4,::1                 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1

   附上命令含义表格:

命令标识授权表中对应的列说明
CREATECreate_priv创建数据库、表或索引
CREATE TEMPORARY TABLESCreate_tmp_table_priv创建临时数据表
CREATE ROUTINECreate_routine_priv创建函数或存储
CREATE VIEWCreate_view_priv创建视图
CREATE USERCreate_user_priv创建用户
EXECUTEExecute_priv执行函数或存储过程
INDEXIndex_priv建立索引
REFERENCESReferences_priv建立约束
DROPDrop_priv删除表
SELECTSelect_priv查询数据
INSERTInsert_priv插入数据
UPDATEUpdate_priv更新数据
DELETEDelete_priv删除数据
LOCK TABLESLock_tables_priv锁定表格
SHOW DATABASESShow_db_priv列出数据库
SHOW VIEWShow_view_priv列出视图
USAGE 只有登录权限,其他权限都没有
ALL 所有权限,除了WITH GRANT OPTION
ALTERAlter_priv更改数据表
ALTER ROUTINEAlter_routine_priv更改函数或存储过程
PROCESSProcess_priv显示连接进程和中断连接进程
FILEFile_priv载入文件
RELOADReload_priv可以用FLUSH
REPLICATION CLIENTRepl_client_priv可以检查Masters和Slaves
REPLICATION SLAVERepl_slave_priv在Slave里的特殊权限
SHUTDOWNShutdown_priv关闭MySQL
WITH GRANT OPTIONGrant_priv可以将自己拥有的权限赋给其他用户
SUPERSuper_priv执行kill线程,change master、purge master logs、set global等命令的权限
create tablespaceCreate_tablespace_priv 创建表空间
EventEvent_priv 确定用户能否创建、修改和删除事件
TriggerTrigger_priv 确定用户能否创建和删除触发器

注意:修改完权限以后 一定要刷新服务,或者重启服务,刷新服务用:FLUSH PRIVILEGES。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值