linux mysql 数据库权限

linux mysql 数据库权限,第1张

hi 楼主,在数据库中创建包含很多,视图,索引,临时表的创建权限都能分开赋予,你可以执行 show privileges 来查看权限参数,我这边就以创建表为例,只包含查询表功能,其他修改,删除,备份没有权限;以下是步骤:

1,create user 'tom'@'%' identified by '123456'---创建用户,无权限;

2, grant create,select on wangxh2.* to tom-----把wangxh2库的所有表的创建和查询赋予tom

3,flush privileges-----刷新权限表才能起效

接下来是测试:

mysql>show databases

+--------------------+

| Database |

+--------------------+

| information_schema |

| test |

| wangxh2|

+--------------------+

3 rows in set (0.06 sec)

mysql>use wangxh2

Database changed

mysql>show tables

+-------------------+

| Tables_in_wangxh2 |

+-------------------+

| test |

+-------------------+

1 row in set (0.00 sec)

mysql>drop test

ERROR 1064 (42000): You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'test' at line 1

mysql>drop table test

ERROR 1142 (42000): DROP command denied to user 'tom'@'localhost' for table 'test'

mysql>select count(*) from test

+----------+

| count(*) |

+----------+

| 33554432 |

+----------+

1 row in set (0.01 sec)

mysql>insert into test values(1)

ERROR 1142 (42000): INSERT command denied to user 'tom'@'localhost' for table 'test'

mysql>delete from test

ERROR 1142 (42000): DELETE command denied to user 'tom'@'localhost' for table 'test'

mysql>update test set id=1

ERROR 1142 (42000): UPDATE command denied to user 'tom'@'localhost' for table 'test'

mysql>create table test1 (id int)

Query OK, 0 rows affected (0.02 sec)

mysql>insert into test1 values(1)

ERROR 1142 (42000): INSERT command denied to user 'tom'@'localhost' for table 'test1'

[mysql@localhost ~]$ mysqldump -u tom -paidengshan wangxh2 >/home/mysql/aa.sql

mysqldump: Got error: 1044: Access denied for user 'tom'@'%' to database 'wangxh2' when using LOCK TABLES

[mysql@localhost ~]$

-----------------------------------------------------------------------------------------

以上测试发现,tom对wangxh2有建表,查询表的权限,但是修改,删除,新增,备份都没有权限,达到你的需求了

工具/材料

linux系统,如redhat或ubuntu

打开 *** 作系统,切换到要修改的文件或目录的父目录。注意,首先切换到root用户群进行更改。

接下来,为了举例,我复制/etc/rc.d下的文件到/tmp下,并切换到/tmp目录。

文件的基本权限分为三种:rwx,权限的对象也有三种:属主(u)、属组(g)、其他(o)。对于文件权限的修改,有两种方式。第一种指定对某一类用户添加(+)或删除(-)某一个权限。在不指定用户时,表示对所有用户修改某一个权限。

第二种是直接指定一个3位的8进制数,它的二进制表示的每一位分别表示该用户的某个权限,0表示没有权限,1表示有权限。

以上的命令只能修改对应的目录自身权限,不能修改目录内部文件的权限。如果要修改目录内部的权限,则使用-R选项,表示递归修改。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8968619.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-23
下一篇 2023-04-23

发表评论

登录后才能评论

评论列表(0条)

保存