安全性与访问控制

数据库的安全性是指保护数据库以防止不合法的使用而造成数据泄露,更改或破坏,所以安全性对于任何一个DBMS来说都是至关重要的.

身份验证,数据库用户权限确认

用户账号管理

root用户

mysql-> select user from mysql.user;

使用create user语句创建MySQL账户

create user user[identified by[password]'password']   //指定创建用户账号格式: 'user_name'@'host_name'    默认的主机是% .    可选项,指定用户账号对应的口令.    可选项,指定散列口令.  hash函数加密

mysq-> select password(456);

mysql-> create user 'zhangsan'@'localhost' identified by '123',       //用户lisi的口令为对明文456使用password()函数加密返回的散列值

    ->                      'lisi'@'localhost' identified by password

   ->                      '*531E182E2F72080AB0740FE2F2D689DBE0146E04';

扫描二维码关注公众号,回复: 11474770 查看本文章

使用drop user语句删除用户账号

drop user user[,user]...

mysql-> drop user lisi@localhost;

使用rename user语句修改用户账号

rename user older_user to new_user[,older_use to new_user]...

mysql-> rename user  'zhangsan'@'localhost' to 'wangwu'@'localhost';

使用set password语句修改用户登录口令

set password[for user]=

  {

    password('new_password')

    |'encrypted password' //表示已被函数password()加密的口令

}

set password for 'username'@'localhost' = password('pass');

使用grant语句为用户授权

grant 

  priv_type[column_list]   //用于指定权限的名称  用于指定权限要授予给表中哪些具体的列

    [,priv_type[(column_list)]]...

  on[object_type] priv_level  //用于指定权限授予的对象和级别  用于指定权限的级别

  to user_specification[,user_specification]...  //用于设定用户的口令,以及指定被授予权限的用户user

  [with grant option]   //可选项,用于实现权限的转移或限制

mysql-> grant select(cust_id,cust_name)

    ->      on mysql_test.cust

   ->       to 'zhangsan'@'localhost';

mysql-> grant select,update                        

    ->  on mysql_test.cust

   ->   to 'liming'@'localhost' identified by '123',   //系统不存在的用户liming和huang,同时创建,并设置对应的系统登录口令

     ->   'huang'@'localhost' identified by '789';  

mysql-> grant all           //授予mysql_test中执行所有数据库操作的权限

    ->  on mysql_test.*

   ->   to 'wangwu'@'localhost';

mysql-> grant create user    //授予创建用户的权限

    ->  on *.*

   ->   to 'wangwu'@'localhost';

mysql-> grant select,update    

    -> on mysql_test.cust

   -> to 'zhou'@'localhost' identified by '123'  //授予系统中不存在的用户zhou权限

  -> with grant option;    //并允许可以将自身的权限授予给其他用户

使用revoke语句撤销用户权限

  revoke

    priv_type[(column_list)]

      [,priv_type[(column_list)]]...

    on[object_type] priv_level

    from user[,user]... 

mysql-> revoke select

    -> on mysql_test.cust

    -> from 'zhou'@'localhost'; //在回收权限的同时不允许删除用户

猜你喜欢

转载自www.cnblogs.com/lsxsx/p/13394290.html