注意:用户操作通常在root用户下进行. 同时在grant语句中的语句' identified by '***'' 可以省略. 如:
mysql> grant all privileges on *.* to 'jerval2'@'localhost'; Query OK, 0 rows affected (0.01 sec)
授权命令GRANT 语句的语法如下:
GRANT privileges (columns) ON what TO user IDENTIFIED BY 'password' WITH GRANT OPTION
其中IDENTIFIED BY 'password'语句在root用户下可以省略(其它用户下没有测试),
>>新建用户
新建用户jerval2,仅本地访问,密码为123:
mysql> insert into mysql.user(host,user,password) values('localhost','jerval2',password('123')); Query OK, 1 row affected, 3 warnings (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
>>修改用户密码为123456.
mysql> update mysql.user set password=password('123456') where user='jerval2' and host='localhost'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
>>为用户指定数据库访问资源
a,授权用户jerval2在mysql库下的所有表的所有操作权限.
mysql> grant all privileges on mysql.* to 'jerval2'@'localhost' identified by '123'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
b,授权用户jerval2在mysql库下的所有表的select,insert,update,delete操作权限.
mysql> grant select,insert,update,delete on mysql.* to 'jerval2'@'localhost' identified by '123'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
>>删除用户
mysql> delete from mysql.user where user='jerval2' and host='localhost'; Query OK, 1 row affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
收藏自网络:
权限信息用user、db、host、tables_priv和columns_priv表被存储在mysql数据库中(即在名为mysql的数据库中)。 权限 列 Context select Select_priv 表 insert Insert_priv 表 update Update_priv 表 delete Delete_priv 表 index Index_priv 表 alter Alter_priv 表 create Create_priv 数据库、表或索引 drop Drop_priv 数据库或表 grant Grant_priv 数据库或表 references References_priv 数据库或表 reload Reload_priv 服务器管理 shutdown Shutdown_priv 服务器管理 process Process_priv 服务器管理 file File_priv 在服务器上的文件存取