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

2021-08-26 05:35:00 字數 2074 閱讀 4159

mysql -uroot -proot

mysql5.7 mysql.user表沒有password欄位改 authentication_string;

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

例子: create user 'dog'@'localhost' identified by '123456';

create user 'dog2'@'localhost' identified by '';

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

host - 指定該使用者在哪個主機上可以登陸,此處的"localhost",是指該使用者只能在本地登入,不能在另外一台機器上遠端登入,如果想遠端登入的話,將"localhost"改為"%",表示在任何一台電腦上都可以登入;也可以指定某台機器可以遠端登入;

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

命令:grant privileges on databasename.tablename to 'username'@'host'

ps: privileges - 使用者的操作許可權,如select , insert , update 等(詳細列表見該文最後面).如果要授予所的許可權則使用all.;databasename - 資料庫名,tablename-表名,如果要授予該使用者對所有資料庫和表的相應操作許可權則可用*表示, 如*.*.

例子: grant select, insert on mq.* to 'dog'@'localhost';

mysql> grant all privileges on mq.* to test@localhost identified by '1234';

query ok, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.01 sec)

ps:必須執行flush privileges; 

命令:set password for 'username'@'host' = password('newpassword');

例子: set password for 'dog2'@'localhost' = password("dog");

命令: revoke privilege on databasename.tablename from 'username'@'host';

說明: privilege, databasename, tablename - 同授權部分.

例子: revoke select on mq.* from 'dog2'@'localhost';

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

具體資訊可以用命令show grants for 'dog'@'localhost'; 檢視.

命令: drop user 'username'@'host';

mysql> show grants for dog@localhost;

| grants for dog@localhost |

| grant usage on *.* to 'dog'@'localhost' |

| grant insert on `mq`.* to 'dog'@'localhost' |

2 rows in set (0.00 sec)

ps:grant usage:mysql usage許可權就是空許可權,預設create user的許可權,只能連庫,啥也不能幹

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

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

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

操作環境 ubuntu1.9 mysql安裝 sudo apt get install mysql server sudo apt get install mysql client安裝完成的mysql在終端可以通過始下命令進入 sudo mysqlmysql5.7 mysql.user表沒有pass...

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

mysql uroot proot mysql5.7 mysql.user表沒有password欄位改 authentication string 一.建立使用者 命令 create user username host identified by password 例子 create user d...