MySQL 許可權管理

2022-05-09 10:09:13 字數 1483 閱讀 3833

1、許可權管理

* mysql 庫的 user 表控制mysql的許可權。

如:mysql> select user,host from user;

| user                       | host |

| debian-sys-maint    | localhost |

| mysql.sys                | localhost |

| phpmyadmin           | localhost |

| root                       | localhost |

資料說明,root這個使用者只能從localhost這個主機登陸到資料庫。

2、 新增乙個mysql使用者賬號,並授權

使用grant命令可以新增mysql使用者

grant例子:

grant all privileges on *.* to test@'localhost' identified by '123' with grant option;

grant命令說明:

all privileges 表示所有許可權,也可以使用select,update等

on 是固定語法

*.* 第乙個*代表所有的資料庫,第二個*代表所有表。也可以寫demo.user代表demo庫的user表

to 為固定語法

identified by '密碼', identified by 也可以不寫,不寫就是不修改密碼

with grant option 代表該使用者可以將自己所擁有的許可權給到別的使用者,這個選項一般建議不加

* grant 例項

1. 授予jack在tp庫的tp_user表上有select和update許可權

grant select,update on tp.tp_user to jack@'localhost' identified by '123';

2. 在第一題的基礎上,再給jack使用者對tp庫的tp_user表有delete許可權

這個時候,jack就有select,update,delete許可權了

grant delete on tp.tp_user to jack@'localhost';

3. 授予test1在tp庫的tp_user表上的姓名和郵箱欄位的select許可權

grant select(name,email) on tp.tp_user to 'test1'@'localhost' identified by '123';

這個時候,test1只能查詢出name與email的資料

3、 修改使用者密碼

set password for '使用者名稱'@'ip'=password('123456');

4、 刪除使用者

drop user '使用者名稱'@'ip'

例如: drop user test@localhost;

5、 檢視使用者的許可權

grants for '使用者名稱'@'ip'

MySQL許可權管理

本文主要講述的是mysql grant命令的例項演示,文中的mysql grant命令的實際操作主要是在mysql 5.0 及以上的相關版本上執行,下面就是對其具體操作步驟的描述,望你在瀏覽之後會有所收穫。mysql 賦予使用者許可權命令的簡單格式可概括為 grant 許可權 on 資料庫物件 to...

mysql 許可權管理

1.新增使用者 方法一 create user wangda localhost identified by password 000000 說明 建立乙個本地的使用者,使用者名為 wangda 密碼為 000000 如果密碼為空,則 identified by password 000000 這個...

mysql許可權管理

mysqladmin u root p password leftpassword 無密碼的話直接回車 任意主機登入host換成 create user username host identified by password privileges all 代表所有許可權 表示全部的資料庫 gran...