新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

MySQL如何使用GRANT授权某用户浏览和修改表权限操作

小编给大家分享一下MySQL如何使用GRANT授权某用户浏览和修改表权限操作,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

专注于为中小企业提供成都做网站、成都网站设计、成都外贸网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业汶上免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了数千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

下面的例子是授权logger用户查询,插入和修改test数据库表记录,但不能删除的一个例子:
C:\Users\duansf>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.13 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db_shop            |
| frag_test          |
| mysql              |
| performance_schema |
| test               |
+--------------------+


mysql> use test
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| workinfo       |
+----------------+
1 row in set (0.03 sec)


mysql> select * from workinfo;        
Empty set (0.12 sec)                      --表记录为空

mysql> grant select,insert,update on test.workinfo to logger@localhost identified by 'timber';     --授权logger用户访问和修改test数据库的workinfo表
Query OK, 0 rows affected (0.14 sec)
mysql> quit
Bye


C:\Users\duansf>mysql -h localhost -u logger -p      --用logger用户登录数据库
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.13 MySQL Community Server (GPL)


Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>


mysql> select * from workinfo;        --可以查询
Empty set (0.12 sec)


mysql> desc workinfo;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| id       | int(10)     | NO   | PRI | NULL    | auto_increment |
| name     | varchar(20) | NO   |     | NULL    |                |
| type     | varchar(10) | YES  |     | NULL    |                |
| address  | varchar(50) | YES  |     | NULL    |                |
| tel      | varchar(20) | YES  |     | NULL    |                |
| wages    | int(11)     | YES  |     | NULL    |                |
| contents | tinytext    | YES  |     | NULL    |                |
| extra    | text        | YES  |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+
8 rows in set (0.02 sec)


mysql> insert into workinfo values(3,'chenfeng','type','zhengzhou','123456',22,1,1);      --有插入权限
Query OK, 1 row affected (0.13 sec)


mysql> select * from workinfo;      --有查询权限
+----+----------+------+-----------+--------+-------+----------+-------+
| id | name     | type | address   | tel    | wages | contents | extra |
+----+----------+------+-----------+--------+-------+----------+-------+
|  3 | chenfeng | type | zhengzhou | 123456 |    22 | 1        | 1     |
+----+----------+------+-----------+--------+-------+----------+-------+
1 row in set (0.00 sec)



mysql> update workinfo set name='duansf' where id=3;         --有修改权限
Query OK, 1 row affected (0.13 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select * from workinfo;
+----+--------+------+-----------+--------+-------+----------+-------+
| id | name   | type | address   | tel    | wages | contents | extra |
+----+--------+------+-----------+--------+-------+----------+-------+
|  3 | duansf | type | zhengzhou | 123456 |    22 | 1        | 1     |
+----+--------+------+-----------+--------+-------+----------+-------+
1 row in set (0.00 sec)


mysql>


mysql> delete from workinfo where id=3;          --无删除权限,以下是报错信息
ERROR 1142 (42000): DELETE command denied to user 'logger'@'localhost' for table
 'workinfo'

看完了这篇文章,相信你对“MySQL如何使用GRANT授权某用户浏览和修改表权限操作”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


网页题目:MySQL如何使用GRANT授权某用户浏览和修改表权限操作
标题链接:http://wjwzjz.com/article/pceeoi.html
在线咨询
服务热线
服务热线:028-86922220
TOP