mysql資料庫建立使用者 賦權 修改使用者密碼

2022-06-13 23:15:20 字數 2308 閱讀 4230

create user lisi identified by '123456';

檢視建立結果:

命令格式:grant privilegescode on dbname.tablename to username@host identified by "password";

命令說明:

privilegescode表示授予的許可權型別,常見有:

all privileges:所有許可權;

select:讀取許可權;

delete:刪除許可權;

update:更新許可權;

create:建立許可權;

drop:刪除資料庫、資料表許可權。

dbname.tablename表示授予許可權的具體庫或表,常用有:

「 *.*」點號表示授予使用者所有資料庫和表的許可權;

dbname.*:授予dbname資料庫所有表的許可權;

dbname.dbtable:授予資料庫dbname中dbtable表的許可權。   

username@host中的host表示允許登入的ip,常見有:

localhost只允許該使用者在本地登入,不能遠端登入;

%:允許遠端登入;

192.168.12.34具體的ip表示只允許該使用者從特定ip登入。

新建乙個資料庫 dblisi:create database dblisi;

賦權李四去使用資料庫dblisi:允許遠端,密碼為123456

grant all privileges on dblisi.* to lisi@'%' identified by '123456';

重新整理許可權:flush privileges;

退出用賬號lisi登入:mysql -u lisi -p

輸入密碼123456

登陸成功後切換資料庫:

可見只有資料庫dblisi的使用權。

update mysql.user set password = password('12345678') where user = 'lisi' ;

注意:在mysql8的版本中授權命令發生了改變,先: create user root@『%』  identified by '123456'; 再:grant all privileges on *.*  to 'root'@'%';

裡面的*和%就自選了。

直接修改登入使用者的密碼:

雖然0 rows affected,重新整理失敗,但是退出去用密碼123可以登入進來;

遠端也能連線:

登入root,修改密碼為123,重新整理,如下:

同樣 0 rows affected,但是重新整理成功;

遠端登入卻失敗:

這是個奇怪的現象。看來修改root密碼用set password並不行。換乙個方式:

update mysql.user set authentication_string=password('123') where user='root';

重新整理:flush privileges;

連線成功!

注意,新版的mysql下authentication_string才是密碼字段。

MySQL建立使用者 資料庫 賦權

在機器上登入mysql mysql u root p1 建立使用者 create user 使用者名稱 localhost identified by 密碼 create user 使用者名稱 identified by 密碼 2 重新整理mysql的系統許可權相關表 flush privilege...

mysql建立資料庫並賦權

1.使用root使用者登入musql資料庫 mysql uroot p密碼 2.建立資料庫labsoft hc create database labsoft hc 3.給資料庫建立單獨使用者labsoft user create user labsoft user 4.給使用者labsoft us...

mysql建立資料庫並賦權

1.使用root使用者登入musql資料庫 mysql uroot p密碼 2.建立資料庫labsoft hc create database if not exists labsoft hcdefault charset utf8 collate utf8 general ci 3.給資料庫建立單...