MySQL 增加使用者和分配許可權

2021-06-22 18:15:17 字數 2345 閱讀 9312

1.新建使用者

//登入mysql

@>mysql -u root -p

@>密碼

//建立使用者

mysql> insert into mysql.user(host,user,password) values(『localhost』,'jeecn』,password(『jeecn』));

//重新整理系統許可權表

mysql>flush privileges;

這樣就建立了乙個名為:jeecn  密碼為:jeecn  的使用者。

//退出後登入一下

mysql>exit;

@>mysql -u jeecn -p

@>輸入密碼

mysql>登入成功

2.為使用者授權

//登入mysql(有root許可權)。我裡我以root身份登入.

@>mysql -u root -p

@>密碼

//首先為使用者建立乙個資料庫(jee***b)

mysql>create database jee***b;

//授權jeecn使用者擁有jeecn資料庫的所有許可權

@>grant all privileges on jee***b.* to jeecn@localhost identified by 『jeecn』;

//重新整理系統許可權表

mysql>flush privileges;

mysql>其它操作

//如果想指定部分許可權給一使用者,可以這樣來寫:

mysql>grant select,update on jee***b.* to jeecn@localhost identified by 『jeecn』;

//重新整理系統許可權表。

mysql>flush privileges;

mysql> grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者位址 identified by 『連線口令』;

許可權1,許可權2,…許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權。

當許可權1,許可權2,…許可權n被all privileges或者all代替,表示賦予使用者全部許可權。

當資料庫名稱.表名稱被*.*代替,表示賦予使用者操作伺服器上所有資料庫所有表的許可權。

使用者位址可以是localhost,也可以是ip位址、機器名字、網域名稱。也可以用』%』表示從任何位址連線。

『連線口令』不能為空,否則建立失敗。

例如:mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by 『123′;

給來自10.163.225.87的使用者jee分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。

mysql>grant all privileges on vtdc.* to [email protected] identified by 『123′;

給來自10.163.225.87的使用者jee分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to [email protected] identified by 『123′;

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

mysql>grant all privileges on *.* to jee@localhost identified by 『123′;

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

3.刪除使用者

@>mysql -u root -p

@>密碼

mysql>delete from user where user=」jeecn」 and host=」localhost」;

mysql>flush privileges;

//刪除使用者的資料庫

mysql>drop database jee***b;

4.修改指定使用者密碼

@>mysql -u root -p

@>密碼

mysql>update mysql.user set password=password(『新密碼』) where user=」jeecn」 and host=」localhost」;

mysql>flush privileges;

mysql>quit;

sqlserver 增加使用者並分配許可權

1 建立使用者 cmd2 create login cmd2 with password 123qwe default database dev cmd create user cmd2 for login cmd2 with default schema dbo 2 給使用者增加資料庫的訪問許可權...

MySQL建立使用者和分配許可權

回顧今天的資料庫實驗 先新建乙個測試資料庫 再建立個表填些資料 檢視使用者並沒有直接的sql語句,而是進入 mysql 資料庫的 user 表 這個mysql庫和user表都是一開始就有的 直接用 select from user 來檢視有什麼使用者 use mysql select from us...

mysql 建立使用者 分配許可權

mysql建立使用者的方法分成三種 insert user表的方法 create user的方法 grant的方法。1 通過create user命令進行建立使用者 指令碼 create user username host identified by password 其中密碼是可選項 例子 cr...