如何給mysql使用者分配許可權

2021-09-06 19:29:15 字數 2154 閱讀 7055

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 [email protected] identified by 『123′;

給來自10.163.225.87的使用者joe分配可對資料庫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的使用者joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。

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

給來自10.163.225.87的使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令(www.111cn.net)為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的提示符下執行下列命令,每個命令以分號結束

from:

Ubuntu中給mysql使用者分配許可權

grant 許可權1,許可權2,許可權n on 資料庫名稱.表名稱 to 使用者名稱 使用者位址 identified by 連線口令 許可權1,許可權2,許可權n代表select,insert,update,delete,create,drop,index,alter,grant,referenc...

Linux下給mysql建立使用者分配許可權

1.新建使用者 登入mysql mysql u root p 密碼 建立使用者 mysql insert into mysql.user host,user,password values localhost jeecn password jeecn 重新整理系統許可權表 mysql flush p...

mysql 建立使用者 分配許可權

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