mysql使用者建立與許可權管理

2021-10-07 09:34:20 字數 1813 閱讀 5546

引數說明:

username:你將建立的使用者名稱

host:指定該使用者在哪個主機上可以登陸,如果是本地使用者可用localhost,如果想讓該使用者可以從任意遠端主機登陸,可以使用萬用字元%

password:該使用者的登陸密碼,密碼可以為空,如果為空則該使用者可以不需要密碼登陸伺服器

例項:create user 『dog』@『localhost』 identified by 『123456』;

create user 『pig』@『192.168.1.101_』 idendified by 『123456』;

create user 『pig』@』%』 identified by 『123456』;

create user 『pig』@』%』 identified by 『』;

create user 『pig』@』%』;

grant privileges on databasename.tablename to 'username'@'host'
說明:privileges:使用者的操作許可權,如select,insert,update等,如果要授予所的許可權則使用all

databasename:資料庫名

tablename:表名,如果要授予該使用者對所有資料庫和表的相應操作許可權則可用表示,如.*

例子: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』;

Mysql使用者與許可權管理

對於root使用者的密碼操作 更改使用者密碼 剛剛安裝完的mysql,只一有個root使用者,密碼為空,而且只能在本機登入!為root加上密碼 123 bin mysqladmin u root password 123 或寫成 bin mysqladmin uroot password 123 加...

mysql 使用者管理與許可權

create user username host identified by password host 僅允許本地使用者登陸使用具體ip或 localhost 允許任意遠端主機登陸使用萬用字元 密碼可設可不設。grant privileges on database.tablesname to ...

mysql 使用者 MySQL使用者與許可權的管理詳解

使用者連線到mysql,可以做各種查詢,這都是mysql使用者與許可權功能在背後維持著操作。使用者與資料庫伺服器互動資料,分為兩個階段 1 你有沒有權連線上來 2 你有沒有權執行本操作 1 你有沒有權連線上來 伺服器如何判斷使用者有沒有權連線上來?依據 1 你從 來?host 2 你是誰?user ...