mysql 常用的命令之使用者篇

來源:互聯網
上載者:User

標籤:mysql

建立使用者: 

create user 使用者名稱;                         --建立一個空密碼使用者.

create user 使用者名稱 IDENTIFIED BY ‘密碼‘;           --建立使用者時建立密碼.

grant select[,insert...] on mysql.user to 使用者名稱 identified by ‘密碼‘;   --建立使用者的同時,授予使用者select mysql資料庫user表的許可權.


更新密碼: 

1. set password=password(‘密碼‘);                --修改目前使用者密碼.

2. set password for 使用者名稱=password(‘密碼‘);         --修改指定使用者密碼.

3. update mysql.user set password=password(‘密碼‘) where user=‘使用者名稱‘  --用update直接修改

 flush privilegs;                                     --更新記憶體使之生效


查看使用者權限:

use mysql

select * from user where User=‘test‘\G;           --格式化查看test使用者的許可權.


刪除使用者:

delete from user where user=‘‘;   --刪除user表中,使用者名稱為空白的列,必加from。防止任務使用者都可以隨便登入

flush privileges;             --重新整理記憶體使修改生效       


給使用者授權:

grant all on mysql.user to [email protected]‘%‘;     --賦予所有名為test的使用者mysql資料庫user表的所有許可權.

grant all on stu.* to [email protected]‘%‘;       --賦予所有test2使用者對stu資料庫的許可權


查詢使用者權限:

select * from mysql.user where user=‘隨便一個使用者名稱‘;   --查詢使用者在資料庫級的許可權

show grants;                              --查詢目前使用者許可權

show grants for 使用者名稱;                       --查詢指定使用者的許可權


回改許可權:

revoke all privileges on mysql.user from test;       --回收test使用者對mysql.user資料表的所有許可權.

revoke select on mysql.user from test2;           --回收test2對mysql.user資料表的select許可權.


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.