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

进入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。(非必要时禁用,实在是太危险了。)

发表评论