首页 > 编程知识 正文

mysql 初始化用户权限,mysql 权限

时间:2023-05-06 12:37:56 阅读:131349 作者:1658

mysql将更改用户权限

thisentrywaspostedbyadminmonday,26苹果,2010

1 .“grant allon *.* to root @”%’identified by‘your password’; “——这个密码也可以顺便设定。

2 .“闪存权限; ”——更新以启用权限。

有关其他mysql管理的信息,请使用mysqladmin命令。 可用于密码的设定等。

有关grant的详细信息,可以看到我的以下转载:

本文中的示例在MySQL 5.0或更高版本上运行。

MySQL授予用户权限的命令的简单格式可以概括如下:

grant权限on数据库对象到用户

另一方面,授权一般数据用户有权查询、插入、更新和删除数据库中的所有表数据。

grantselectontestdb.* to common _ user @’%’

grantinsertontestdb.* to common _ user @’%’

grantupdateontestdb.* to common _ user @’%’

grantdeleteontestdb.* to common _ user @’%’

或者,用MySQL命令替换。

授权选择、插入、更新、deleteontestdb.* to common _ user @’%’

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

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

grantcreateontestdb.* to developer @’192.168.0.%’;

grantalterontestdb.* to developer @’192.168.0.%’;

grantdropontestdb.* to developer @’192.168.0.%’;

grant操作MySQL外键权限。

grantreferencesontestdb.* to developer @’192.168.0.%’;

授权操作MySQL临时表权限。

grantcreatetemporarytablesontestdb.* to developer @’192.168.0.%’;

grant操作MySQL索引权限。

grantindexontestdb.* to developer @’192.168.0.%’;

grant操作MySQL视图并显示视图的源代码权限。

grantcreateviewontestdb.* to developer @’192.168.0.%’;

grantshowviewontestdb.* to developer @’192.168.0.%’;

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

grantcreateroutineontestdb.* to developer @’192.168.0.%’; — now,can show procedure status

grantalterroutineontestdb.* to developer @’192.168.0.%’; — now,you can drop a procedure

grantexecuteontestdb.* to developer @’192.168.0.%’;

三.管理具有授权普通DBA的MySQL数据库的权限。

grantallprivilegesontestdbtodba @’localhost’

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

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

grant allon *.* to DBA @’localhost’

五、MySQL grant权限可以分别在多个级别发挥作用。

1 .授权作用于整个MySQL服务器:

grantselecton *.* to DBA @ localhost; — dba可以查询MySQL中所有数据库的表。

grant allon *.* todba@localhost; — dba可以管理MySQL中的所有数据库

2 .授权作用于单个数据库:

grantselectontestdb.* to DBA @ localhost; — dba可以查询testdb中的表。

3 .地面作用

在单个数据表上:

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’

六、查看 MySQL 用户权限

查看当前用户(自己)权限:

show grants;

查看其他 MySQL 用户权限:

show grants for dba@localhost;

七、撤销已经赋予给 MySQL 用户权限的权限。

revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

grant all on *.* to   dba@localhost;

revoke all on *.* from dba@localhost;

八、MySQL grant、revoke 用户权限注意事项

1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。

2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“

grant select on testdb.* to dba@localhost with grant option;

这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。

Category: Post

You can follow any responses to this entry via RSS.

Comments are currently closed, but you can trackback from your own site.

=========================================================================

1.创建用户并授权

grant语句的语法:

grant privileges (columns) on what to user identified by "password" with grant option

要使用该句型,需确定字段有:

privileges 权限指定符权限允许的操作

alter 修改表和索引

create 创建数据库和表

delete 删除表中已有的记录

drop 抛弃(删除)数据库和表

index 创建或抛弃索引

insert 向表中插入新行

reference 未用

select 检索表中的记录

update 修改现存表记录

file 读或写服务器上的文件

process 查看服务器中执行的线程信息或杀死线程

reload 重载授权表或清空日志、主机缓存或表缓存。

shutdown 关闭服务器

all 所有;all privileges同义词

usage 特殊的“无权限”权限

以上权限分三组:

第一组:适用于数据库、表和列如:alter create delete drop index insert select update

第二组:数管理权限 它们允许用户影响服务器的操作 需严格地授权 如:file process reload shut*

第三组:权限特殊 all意味着“所有权限” uasge意味着无权限,即创建用户,但不授予权限

columns

权限运用的列(可选)并且你只能设置列特定的权限。如果命令有多于一个列,应该用逗号分开它们。

what

权限运用的级别。权限可以是全局,定数据库或特定表.

user

权限授予的用户,由一个用户名和主机名组成,许两个同名用户从不同地方连接.缺省:mysql用户password

赋予用户的口令(可选),如果你对用户没有指定identified by子句,该用户口令不变.

用identified by时,口令字符串用改用口令的字面含义,grant将为你编码口令.

注:set password使用password()函数

with grant option

用户可以授予权限通过grant语句授权给其它用户(可选)

实例讲解:

grant all on db_book.* to huaying@koowo.com identified by "yeelion" 只能在本地连接

grant all on db_book.* to huaying@vpn.koowo.com identified by "yeeliong" 允许从此域连接

grant all on db_book.* to huaying@% identified by "yeelion" 允许从任何主机连接

注:"%"字符起通配符作用,与like模式匹配的含义相同。

grant all on db_book.* to huaying@%.koowo.com identified by "yeelion";

允许huaying从koowo.com域的任何主机连接

grant all on db_book.* to huaying@192.168.1.189 identified by "yeelion"

grant all on db_book.* to huaying@192.168.1.% identified by "yeelion"

grant all on db_book.* to huaying@192.168.1.0/17 identified by "yeelion"

允许从单IP 段IP或一子网IP登陆

grant all on *.* to huaying@localhost identified by "yeelion" with grant option

添加超级用户huaying 可在本地登陆做任何操作.

grant reload on *.* to huaying@localhost identified by "yeelion" 只赋予reload权限

grant all on db_book to huaying@koowo.com indetified by "yeelion" 所有权限

grant select on db_book to huaying@% indetified by "yeelion" 只读权限

grant select,insert,delete,update on db_book to huaying@koowo.com indetified by "yeelion"

只有select,insert,delete,update的权限

grant select on db_book.storybook to huaying@localhost indetified by "yeelion" 只对表

grant update (name) on db_book.storybook to huaying@localhost 只对表的name列 密码不变

grant update (id,name,author) on db_book.storybook to huaying@localhost 只对表的多列

grant all on book.* to ""@koowo.com 允许koowo.com域中的所有用户使用长情的雨

grant all on book.* to huaying@%.koowo.com indetified by "yeelion" with grant option

允许huaying对长情的雨所有表的管理员授权.

2.撤权并删除用户

revoke的语法类似于grant语句

to用from取代,没有indetifed by和with grant option子句. 如下:

revoke privileges (columns) on what from user

user:必须匹配原来grant语句的你想撤权的用户的user部分。

privileges:不需匹配,可以用grant语句授权,然后用revoke语句只撤销部分权限。

revoke语句只删权限不删用户,撤销了所有权限后user表中用户记录保留,用户仍然可以连接服务器.

要完全删除一个用户必须用一条delete语句明确从user表中删除用户记录:

delete from user where user="huaying"

flush privileges; 重载授权表

注:使用grant和revoke语句时,表自动重载,而你直接修改授权表时不是.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。