數據庫授權


1.數據庫授權

  為用戶授權

  授權格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by "密碼"; 

  1.1 登錄MYSQL(有ROOT權限),這里以ROOT身份登錄:

  @>mysql -u root -p

  @>密碼

  1.2 首先為用戶創建一個數據庫(testDB):

  mysql>create database testDB;

  1.3 授權test用戶擁有testDB數據庫的所有權限(某個數據庫的所有權限):

   mysql>grant all privileges on testDB.* to test@localhost identified by '1234';

   mysql>flush privileges;//刷新系統權限表

  格式:grant 權限 on 數據庫.* to 用戶名@登錄主機 identified by "密碼"; 

  1.4 如果想指定部分權限給一用戶,可以這樣來寫:

  mysql>grant select,update on testDB.* to test@localhost identified by '1234';

  mysql>flush privileges; //刷新系統權限表

  1.5 授權test用戶擁有所有數據庫的某些權限:   

  mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

       //test用戶對所有數據庫都有select,delete,update,create,drop 權限。

    //@"%" 表示對所有非本地主機授權,不包括localhost。(localhost地址設為127.0.0.1,如果設為真實的本地地址,不知道是否可以,沒有驗證。)

   //對localhost授權:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。

收回權限:

revoke 權限 on 數據庫對象 from 用戶

轉自:【http://www.cnblogs.com/fly1988happy/archive/2011/12/15/2288554.html】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM