如何給mysql使用者指派許可權

來源:互聯網
上載者:User


1,Mysql下建立新的使用者

文法:

1.create user 使用者名稱 identified by '密碼';

例:create user xiaogang identified by '123456';

新建立的使用者,預設情況下是沒有任何許可權的。


2. 如何給使用者指派許可權

文法:

1.grant 許可權 on 資料庫.資料表 to '使用者' @ '主機名稱';

例:給 xiaogang 分配所有的許可權

grant all on *.* to 'xiaogang'@'%';

這個時候 xiaogang 就擁有了 所有許可權了

3 如何更精準的控制使用者的許可權呢?

1.grant 許可權 on 資料庫.資料表 to '使用者' @ '主機名稱';


例:讓 xiaogang 有查詢 tmp 資料庫 tmp1 表的許可權;

grant select on temp.temp1 to 'xiaogang'@'%';   //這個時候 xiaogang 就具有查詢temp小的temp1的許可權了。


例如:

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by ‘123′;

給來自10.163.225.87的使用者joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。
 
mysql>grant all privileges on vtdc.* to joe@10.163.225.87 identified by ‘123′;

給來自10.163.225.87的使用者joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。
 
mysql>grant all privileges on *.* to joe@10.163.225.87 identified by ‘123′;

給來自10.163.225.87的使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。
 
mysql>grant all privileges on *.* to joe@localhost identified by ‘123′;

給本機使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。
 

4. 如何收回 許可權,一般指有root使用者才具有該許可權

文法:

1.revoke 許可權 on  資料庫.資料表 from '使用者'@'主機名稱';

例:收回 xiaogang的所有許可權

revoke all on *.* from 'xiaogang' @'%';

好了下面我個把步驟總結一下很具體的一個過程


第一步:mysql服務的啟動和停止

net stop mysql

net start mysql

第二步:直接登陸mysql

文法如下: mysql -u使用者名稱 -p使用者密碼

鍵入命令mysql -uroot -p, 斷行符號後提示你輸入密碼,輸入123456,然後斷行符號即可進入到mysql中了,mysql的提示符是:

mysql>

注意,如果是串連到另外的機器上,則需要加入一個參數-h機器IP

第三步:增加新使用者

格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"

如,增加一個使用者user1密碼為password1,讓其可以在本機上登入, 並對所有資料庫有查詢、插入、修改、刪除的許可權。首先用以root使用者連入mysql,然後鍵入以下命令:

grant select,insert,update,delete on *.* to user1@localhost Identified by "password1";

如果希望該使用者能夠在任何機器上登陸mysql,則將localhost改為"%"。

如果你不想user1有密碼,可以再打一個命令將密碼去掉。

grant select,insert,update,delete on mydb.* to user1@localhost identified by "";

第四步: 操作資料庫

登入到mysql中,然後在mysql的提示符下運行下列命令,每個命令以分號結束

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.