mysql建立使用者與授權

2021-10-07 05:25:45 字數 1666 閱讀 9793

進入資料庫

[root@localhost ~]# mysql -u root -p

enter password:

建立使用者 :

命令:create user 'username'@'host' identified by 'password';

mysql> select host,user,authentication_string from mysql.user

-> ;

說明:

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

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

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

mysql> create database sms_backups_data;

query ok, 1 row affected (0.02 sec)

mysql> grant all  on sms_backups_data.*  to 'xiaozuo'@'%' ;

query ok, 0 rows affected (0.01 sec)

說明:

privileges:使用者的操作許可權,如select,insert,update等,如果要授予所的許可權則使用all

databasename:資料庫名

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

命令: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建立使用者與授權

一 建立使用者 命令 create user username host identified by password 說明 username 你將建立的使用者名稱,host 指定該使用者在哪個主機上可以登陸,如果是本地使用者可用localhost,如果想讓該使用者可以從任意遠端主機登陸,可以使用萬...

MySQL建立使用者與授權

1 建立使用者,建立使用者的時候不分配任何許可權 create user 使用者名稱 訪問 identified by 密碼 2 刪除使用者 drop user 使用者名稱 3 分配許可權 grant 許可權 on 資料庫.表 to 使用者名稱 訪問 identified by 密碼 grant s...

MySQL建立使用者與授權

在linux 上的新裝的mysql 需要修改root 密碼 set password for root localhost password root 一,建立使用者 命令 create user username host identified by password 說明 username 你將...