上網找過資料說要進入mysql數據庫在進行這些操做,我試了發現不進數據庫和進入mysql數據庫效果都同樣mysql
網上有的直接建立並賦權,像醬紫的:sql
grant all privileges *.* to '要建立的用戶'@'localhost' identified by '自定義密碼';數據庫
我在mysql8試了不行(8版本如下還沒試過),要先建立用戶再進行賦權,不能同時進行ide
建立用戶ip
create user 'test1'@'localhost' identified by '‘密碼';it
flush privileges;刷新權限io
其中localhost指本地纔可鏈接test
能夠將其換成%指任意ip都能鏈接date
也能夠指定ip鏈接select
修改密碼
Alter user 'test1'@'localhost' identified by '新密碼';
flush privileges;
受權
grant all privileges on *.* to 'test1'@'localhost' with grant option;
with gran option表示該用戶可給其它用戶賦予權限,但不可能超過該用戶已有的權限
好比a用戶有select,insert權限,也可給其它用戶賦權,但它不可能給其它用戶賦delete權限,除了select,insert之外的都不能
這句話可加可不加,視狀況而定。
all privileges 可換成select,update,insert,delete,drop,create等操做
如:grant select,insert,update,delete on *.* to 'test1'@'localhost';
第一個*表示通配數據庫,可指定新建用戶只可操做的數據庫
如:grant all privileges on 數據庫.* to 'test1'@'localhost';
第二個*表示通配表,可指定新建用戶只可操做的數據庫下的某個表
如:grant all privileges on 數據庫.指定表名 to 'test1'@'localhost';
查看用戶受權信息
show grants for 'test1'@'localhost';
撤銷權限
revoke all privileges on *.* from 'test1'@'localhost';
用戶有什麼權限就撤什麼權限
刪除用戶
drop user 'test1'@'localhost';