mysql的賬戶管理

來源:互聯網
上載者:User

標籤:let   使用方法   回收   str   許可權列表   ring   mysql資料庫   撤銷   auth   

mysql中賬戶管理:

1 查看所有使用者:
所有使用者及許可權資訊都儲存在mysql資料庫中的user表中
查看user表的結構
desc user\G;

主要欄位:
host: 表示允許訪問的主機
user: 表示使用者名稱
authentication_string: 加密後的密碼
查看所有使用者:
select host,user,authentication_string from user;

2 建立賬戶和授予許可權:
需要使用賬戶登入後操作 例如使用root
常用許可權:create alter drop insert update delete select
分配所有許可權:all privileges

建立賬戶並授予許可權:grant 許可權列表 on 資料庫 to "使用者名稱"@"訪問主機" identified by "密碼";

舉例:
1 登入root: mysql -u root -p
2 grant all privileges on python.* "py"@"%" identified by "123";
-- python資料庫下所有表 擁有所有許可權
-- 使用者名稱py, %表示可以使用任意ip登入
-- 123為密碼
3 退出root: quit;
4 登入py: mysql -u py -p

3 授權: grant 許可權 on 資料庫 to 賬戶1,賬戶2... with grant option;


4 查看某一個使用者有哪些許可權: show grants for 使用者名稱;

5 回收許可權: 用root登入後操作
撤銷某使用者的某許可權: revoke 許可權列表 on 資料庫名.* from "使用者名稱"@"主機";

6 修改密碼:
方法1 不登入,在終端中: mysqladmin -u 使用者名稱 -p password "新密碼"
方法2 使用root登入,修改mysql資料庫中user表
使用password()函數進行加密存入資料庫
修改資料庫之後要重新整理許可權才有效

在root登入狀態下:
改user表:
update user set authentication_string = password("新密碼") where user = "使用者名稱";
重新整理許可權:
flush privileges;

7 刪除賬戶:
方法1 使用root登入後:
drop user "使用者名稱"@"主機";

方法2 使用root登入刪除mysql庫的user表中資料
delete from user where user = "使用者名稱";
操作後必須重新整理許可權: flush privileges

推薦使用方法1,如果主機的字母大寫時候,方法1會無效,再使用方法2。



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.