linux mysql更改用户权限

2017-01-09 10:55:07

ed by admin Monday, 26 April, 2010

1.“grant all on *.* to root@’%’ identified by ‘yourpassword’;”——这个还可以顺带设置密码。
2.“flush privileges; ”——刷新一下,让权限生效。
mysql的一些其他的管理,可以用mysqladmin命令。可以用来设置密码什么的。

grant方面的详细信息可以看我下面的转载:
本文实例,运行于 MySQL 5.0 及以上版本。

MySQL 赋予用户权限命令的简单格式可概括为:

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

一、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’

六、查看 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登陆

注:有时 用户@IP 需用引号 如"huaying@192.168.1.0/17"

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域中的所有用户使用库book

 

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

允许huaying对库book所有表的管理员授权.

 

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语句时,表自动重载,而你直接修改授权表时不是.

发表评论:

  • Nickname_55 :When someone writes an piece of writing heshe maintains the thought of a user in hisher mind that how a user can know it Thus thats why this post is amazing Thanks

  • Nickname_152 :Have you ever considered about adding a little bit more than just your articles I mean what you say is fundamental and all Nevertheless think of if you added some great pictures or video clips to give your posts more "pop" Your content is excellent but with images and video clips this blog could undeniably be one of the best in its field Fantastic blog

  • Nickname_196 :Hi there I realize this is kind of offtopic but I needed to ask Does operating a wellestablished blog such as yours require a massive amount work Im completely new to writing a blog however I do write in my diary every day Id like to start a blog so I can easily share my personal experience and thoughts online Please let me know if you have any kind of ideas or tips for new aspiring bloggers Appreciate it

  • Nickname_202 :always i used to read smaller articles that as well clear their motive and that is also happening with this piece of writing which I am reading now

  • Nickname_257 :Actually when someone doesnt be aware of after that its up to other users that they will assist so here it takes place

  • Nickname_581 :I am genuinely grateful to the owner of this web site who has shared this wonderful post at at this place

  • Nickname_737 :Hi there would you mind letting me know which web host youre working with Ive loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot quicker then most Can you suggest a good hosting provider at a reasonable price Kudos I appreciate it

  • Nickname_1178 :What you said made a lot of sense However what about this suppose you composed a catchier title I am not saying your content is not good but what if you added a post title that makes people desire more I mean 无夜游魂 is kinda plain You ought to peek at Yahoos front page and see how they create news titles to get people interested You might try adding a video or a pic or two to grab people interested about what youve written Just my opinion it could bring your posts a little livelier

  • Nickname_1255 :Remarkable issues here I am very happy to see your article Thank you a lot and Im having a look forward to contact you Will you please drop me a email

  • Nickname_1394 :Good response in return of this issue with real arguments and explaining the whole thing on the topic of that

  • Nickname_2040 :I read this article completely concerning the resemblance of hottest and preceding technologies its remarkable article

  • Nickname_2063 :hey there and thank you for your information – I have definitely picked up anything new from right here I did however expertise some technical issues using this web site since I experienced to reload the web site lots of times previous to I could get it to load correctly I had been wondering if your hosting is OK Not that Im complaining but sluggish loading instances times will often affect your placement in google and can damage your quality score if ads and marketing with Adwords Anyway Im adding this RSS to my email and could look out for a lot more of your respective interesting content Make sure you update this again soon

  • Nickname_2094 :Its awesome to pay a visit this web page and reading the views of all mates on the topic of this paragraph while I am also keen of getting familiarity

  • Nickname_2242 :Its awesome to pay a visit this site and reading the views of all colleagues regarding this post while I am also eager of getting knowhow

  • Nickname_2247 :Ive been browsing online more than three hours today yet I never found any interesting article like yours It is pretty worth enough for me In my opinion if all web owners and bloggers made good content as you did the internet will be a lot more useful than ever before

  • Nickname_2295 :Hello i think that i saw you visited my website so i came to “return the favor”Im attempting to find things to improve my siteI suppose its ok to use a few of your ideas

  • Nickname_2358 :Quality articles or reviews is the secret to invite the people to pay a visit the site thats what this site is providing

  • Nickname_2404 :Hi there This blog post could not be written much better Looking through this post reminds me of my previous roommate He continually kept preaching about this Ill send this information to him Fairly certain hell have a good read Many thanks for sharing

  • Nickname_2500 :You really make it seem so easy with your presentation but I find this topic to be really something that I think I would never understand It seems too complex and very broad for me Im looking forward for your next post Ill try to get the hang of it

  • Nickname_2534 :Does your blog have a contact page Im having trouble locating it but Id like to shoot you an email Ive got some recommendations for your blog you might be interested in hearing Either way great site and I look forward to seeing it expand over time

  • Nickname_2560 :I think this is among the most vital info for me And im glad reading your article But want to remark on few general things The site style is wonderful the articles is really excellent : D Good job cheers

  • Nickname_2717 :This info is worth everyones attention Where can I find out more

  • Nickname_2761 :I do not know if its just me or if everyone else experiencing issues with your blog It appears as though some of the text within your content are running off the screen Can somebody else please comment and let me know if this is happening to them too This might be a issue with my web browser because Ive had this happen before Thank you

  • Nickname_2796 :I was wondering if you ever considered changing the page layout of your site Its very well written; I love what youve got to say But maybe you could a little more in the way of content so people could connect with it better Youve got an awful lot of text for only having 1 or two images Maybe you could space it out better

  • Nickname_2944 :Im really inspired along with your writing skills as well as with the structure to your weblog Is that this a paid subject matter or did you modify it your self Either way keep up the excellent quality writing its rare to peer a nice blog like this one today

  • Nickname_3089 :each time i used to read smaller content that as well clear their motive and that is also happening with this paragraph which I am reading at this place

  • Nickname_3132 :I know this if off topic but Im looking into starting my own blog and was curious what all is needed to get set up Im assuming having a blog like yours would cost a pretty penny Im not very internet savvy so Im not 100 certain Any tips or advice would be greatly appreciated Thank you

  • Nickname_3170 :naturally like your website but you have to test the spelling on several of your posts Several of them are rife with spelling problems and I in finding it very bothersome to tell the reality nevertheless Ill surely come back again

  • Nickname_3242 :I always used to study piece of writing in news papers but now as I am a user of internet thus from now I am using net for articles or reviews thanks to web

  • Nickname_3247 :Hello There I discovered your blog using msn This is an extremely smartly written article Ill make sure to bookmark it and come back to read extra of your useful information Thanks for the post I will definitely comeback

  • Nickname_3437 :I seriously love your site Very nice colors theme Did you make this web site yourself Please reply back as Im attempting to create my own blog and want to know where you got this from or exactly what the theme is called Thank you

  • Nickname_4059 :Highly descriptive blog I liked that bit Will there be a part 2

  • Nickname_4191 :Ive been surfing online more than 4 hours today yet I never found any interesting article like yours It is pretty worth enough for me Personally if all website owners and bloggers made good content as you did the net will be a lot more useful than ever before

  • Nickname_4196 :Hi there mates fastidious paragraph and good arguments commented at this place I am genuinely enjoying by these

  • Nickname_4357 :Actually no matter if someone doesnt be aware of then its up to other people that they will assist so here it takes place

  • Nickname_4382 :I dont know whether its just me or if perhaps everyone else experiencing problems with your site It seems like some of the written text in your posts are running off the screen Can somebody else please comment and let me know if this is happening to them too This may be a issue with my internet browser because Ive had this happen before Thanks

  • Nickname_4779 :Why viewers still use to read news papers when in this technological globe all is presented on web

  • Nickname_4798 :Howdy just wanted to give you a quick heads up The text in your post seem to be running off the screen in Ie Im not sure if this is a format issue or something to do with browser compatibility but I thought Id post to let you know The design and style look great though Hope you get the problem solved soon Cheers

  • Nickname_4941 :Wow that was odd I just wrote an very long comment but after I clicked submit my comment didnt appear Grrrr well Im not writing all that over again Regardless just wanted to say fantastic blog

  • Nickname_5050 :Whats up yes this article is actually nice and I have learned lot of things from it regarding blogging thanks

  • Nickname_5052 :Aw this was an incredibly nice post Taking a few minutes and actual effort to generate a really good article… but what can I say… I procrastinate a whole lot and never seem to get nearly anything done

  • Nickname_5171 :Just want to say your article is as astounding The clearness in your post is simply cool and i can assume youre an expert on this subject Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post Thanks a million and please keep up the rewarding work

  • Nickname_5458 :I was curious if you ever thought of changing the layout of your site Its very well written; I love what youve got to say But maybe you could a little more in the way of content so people could connect with it better Youve got an awful lot of text for only having one or two pictures Maybe you could space it out better

  • Nickname_5850 :Yes Finally something about

  • Nickname_6389 :This site really has all of the information and facts I needed concerning this subject and didnt know who to ask

  • Nickname_6471 :My brother suggested I might like this web site He was entirely right This post actually made my day You can not imagine just how much time I had spent for this information Thanks

  • Nickname_6503 :Your style is really unique compared to other people Ive read stuff from I appreciate you for posting when youve got the opportunity Guess Ill just bookmark this site

  • Nickname_6560 :Hello its me I am also visiting this web page daily this website is really pleasant and the users are really sharing fastidious thoughts

  • Nickname_6692 :Heya im for the first time here I came across this board and I find It really useful it helped me out much I hope to give something back and help others like you helped me

  • Nickname_6956 :Hello colleagues good paragraph and nice arguments commented here I am in fact enjoying by these

  • Nickname_7237 :I know this if off topic but Im looking into starting my own blog and was curious what all is needed to get set up Im assuming having a blog like yours would cost a pretty penny Im not very web smart so Im not 100 certain Any suggestions or advice would be greatly appreciated Many thanks

  • Nickname_7394 :Heya just wanted to give you a quick heads up and let you know a few of the images arent loading properly Im not sure why but I think its a linking issue Ive tried it in two different internet browsers and both show the same outcome

  • Nickname_7415 :Whats up mates its wonderful post about cultureand completely explained keep it up all the time

  • Nickname_7919 :That is really attentiongrabbing Youre an overly professional blogger Ive joined your rss feed and stay up for in the hunt for extra of your magnificent post Additionally I have shared your website in my social networks

  • Nickname_7993 :This is a topic thats close to my heart Thank you Exactly where are your contact details though

  • Nickname_8037 :fantastic post very informative I wonder why the other specialists of this sector dont realize this You should continue your writing I am confident you have a great readers base already

  • Nickname_8086 :Superb website you have here but I was curious about if you knew of any message boards that cover the same topics talked about here Id really love to be a part of community where I can get suggestions from other knowledgeable individuals that share the same interest If you have any suggestions please let me know Appreciate it

  • Nickname_8268 :Thank you for another informative site The place else could I am getting that type of info written in such an ideal manner Ive a undertaking that I am simply now operating on and I have been on the look out for such information

  • Nickname_8365 :all the time i used to read smaller articles or reviews which also clear their motive and that is also happening with this post which I am reading at this place

  • Nickname_8367 :Simply want to say your article is as astonishing The clearness for your publish is simply great and i can assume youre a professional on this subject Fine with your permission allow me to grasp your RSS feed to keep updated with coming near near post Thank you one million and please keep up the enjoyable work

  • Nickname_8572 :Fantastic post but I was wanting to know if you could write a litte more on this topic Id be very thankful if you could elaborate a little bit more Cheers

  • Nickname_8642 :After I initially left a comment I seem to have clicked the Notify me when new comments are added checkbox and from now on each time a comment is added I receive four emails with the same comment Perhaps there is an easy method you are able to remove me from that service Thanks a lot

  • Nickname_8687 :Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates Ive been looking for a plugin like this for quite some time and was hoping maybe you would have some experience with something like this Please let me know if you run into anything I truly enjoy reading your blog and I look forward to your new updates

  • Nickname_8695 :Hello i feel that i noticed you visited my site so i got here to go back the preferI am trying to in finding things to improve my web siteI guess its ok to use a few of your concepts

  • Nickname_8912 :Thank you Ive recently been searching for information approximately this topic for ages and yours is the best I have came upon till now However what about the conclusion Are you positive about the supply

  • Nickname_9137 :Im truly enjoying the design and layout of your site Its a very easy on the eyes which makes it much more pleasant for me to come here and visit more often Did you hire out a designer to create your theme Excellent work

  • Nickname_9329 :Howdy i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam feedback If so how do you stop it any plugin or anything you can recommend I get so much lately its driving me mad so any help is very much appreciated

  • Nickname_9507 :Its such as you learn my thoughts You appear to know a lot about this like you wrote the e book in it or something I believe that you just can do with some pc to pressure the message house a bit however other than that that is great blog A great read Ill definitely be back

  • Nickname_9738 :We are a gaggle of volunteers and starting a new scheme in our community Your site offered us with helpful info to work on Youve performed a formidable job and our whole community might be grateful to you

  • Nickname_9808 :Hello I know this is kinda off topic however Id figured Id ask Would you be interested in exchanging links or maybe guest authoring a blog article or viceversa My site addresses a lot of the same subjects as yours and I think we could greatly benefit from each other If youre interested feel free to shoot me an email I look forward to hearing from you Superb blog by the way

  • Nickname_9915 :WOW just what I was looking for Came here by searching for Kúpiť CNC vŕtačku

  • Nickname_9949 :Whats up just wanted to mention I liked this article It was funny Keep on posting

Powered by PHP 学习者(mail:517730729@qq.com)

原百度博客:http://hi.baidu.com/ssfnadn

备案号:闽ICP备17000564号-1

开源中国 PHPCHINA