实例介绍命令行下向mysql添加新用户并分配权限

2007年09月29日 - 未有留言 - 学习笔记 - 浏览:4,577 | 大小:   | 繁體 | English | Short URL:http://bit.ly/ao37pK

进入mysql的bin目录后
命令格式如下:

bin>mysql -u root -p

回车后输入密码
命令格式
grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;

权限:
select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file

如果允许全部权限,可以用all或者all privileges代替以上权限。

例如:

mysql>grant select,insert,update,delete,create,drop on data1.table1 to austin@192.168.1.1 identified by '123';

给来自192.168.1.1的用户austin分配可对数据库data1的table1表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。

mysql>grant all privileges on data1.* to austin@192.168.1.1 identified by '123';

给来自192.168.1.1的用户austin分配可对数据库data1所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to austin@192.168.1.1 identified by '123';

给来自192.168.1.1的用户austin分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to austin@localhost identified by '123';

给本机用户austin分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。

mysql>grant all privileges on *.* to austin@* identified by '123';

给任意连接过来的用户austin分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。(非必要时禁用,实在是太危险了。)

本文作者:施炜煜
原文链接:http://firefore.com/2007/09/mysql-add-newuser.html
发布于:2007年09月29号   最后修订在:2009年04月17号
版权声明:转载时请以超链接形式标明文章原始出处和作者信息。
读过这篇日志的读者同时也读了:

>欢迎您的来访。喜欢这篇文章么? 发表一下您的看法 好让我们能交流交流一下。
>建议您 订阅这里的RSS,这样您及时地获取更多精彩内容!
>Permalink:http://firefore.com/2007/09/mysql-add-newuser.html
>Trackback Address:http://firefore.com/2007/09/mysql-add-newuser.html/trackback


您也可以使用微博账号登陆