MySQL5 7建立使用者並授權,設定允許遠端連線

2021-09-22 07:50:19 字數 1840 閱讀 6626

create user 'username'@'host' identified by 'password';
create user 'dog'@'localhost' identified by '123456';

create user 'pig'@'192.168.1.101' identified by '123456';

create user 'pig'@'%' identified by '123456';

create user 'pig'@'%' identified by '';

create user 'pig'@'%';

grant privileges on databasename.tablename to 'username'@'host';
grant select, insert on test.user to 'pig'@'%';

grant all on *.* to 'pig'@'%';

grant all on maindataplus.* to 'pig'@'%';

用以上命令授權的使用者不能給其它使用者授權,如果想讓該使用者可以授權,用以下命令:

grant privileges on databasename.tablename to 'username'@'host' with grant option;
set password for 'username'@'host' = password('newpassword');
如果是當前登陸使用者用:

set password = password("newpassword");
set password for 'pig'@'%' = password("123456");
revoke privilege on databasename.tablename from 'username'@'host';
privilege, databasename, tablename:同授權部分

revoke select on *.* from 'pig'@'%';
假如你在給使用者'pig'@'%'授權的時候是這樣的(或類似的):grant select on test.user to 'pig'@'%',則在使用revoke select on *.* from 'pig'@'%';命令並不能撤銷該使用者對test資料庫中user表的select操作。相反,如果授權使用的是grant select on *.* to 'pig'@'%';revoke select on test.user from 'pig'@'%';命令也不能撤銷該使用者對test資料庫中user表的select許可權。

具體資訊可以用命令show grants for 'pig'@'%';檢視。

drop user 'username'@'host';
最後一步就是重新整理許可權:

flush privileges;

mysql5 7建立新使用者並給授權指定的資料庫許可權

1 使用 root 管理員登陸 mysql mysql uroot p 2 建立新使用者 create user cpsadmin identified by cpsadmin123 所有情況都能訪問 localhost 本機才能訪問 111.222.33.44 指定 ip 才能訪問 3 給該使用者...

mysql5 7建立新使用者並給授權指定的資料庫許可權

1 使用 root 管理員登陸 mysql mysql uroot p 2 建立新使用者 create user cpsadmin identified by cpsadmin123 所有情況都能訪問 localhost 本機才能訪問 111.222.33.44 指定 ip 才能訪問 3 給該使用者...

MySQL5 7 新增使用者 刪除使用者與授權

mysql uroot proot mysql5.7 mysql.user表沒有password欄位改 authentication string 命令 create user username host identified by password 例子 create user dog local...