Mysql使用者管理 建立 刪除等

2021-09-19 11:21:24 字數 2444 閱讀 3210

## 建立無任何許可權的使用者,all代表賦予所有許可權,也可以指定具體許可權(select、update等)

grant

usageon*

.*to'user2'@'localhost' identified by '

123456' with

grant

option

;

使用grant給使用者新增許可權,許可權會自動疊加,不會覆蓋之前授予的許可權,比如你先給使用者新增乙個select許可權,後來又給使用者新增了乙個insert許可權,那麼該使用者就同時擁有了select和insert許可權。

## 第一種方式:直接查表

select

*from mysql.

user

;## 第二種方式

## 檢視當前登入使用者的許可權

show grants;

## 指定使用者

show grants for

'user2'

@'localhost'

;

## 建立的新使用者沒有任何許可權

insert

into mysql.

user

(user

,host,password,ssl_cipher,x509_issuer,x509_subject)

values

('user3'

,'localhost'

,'123456',''

,'',''

);

注意:使用這種方法建立的使用者密碼是明文的,而在登入連線時,mysql認為密碼需要先加密,所以是登入不上去的,解決方法有以下兩種

## 第一種方式:在insert時就將密碼加密

insert

into mysql.

user

(user

,host,password,ssl_cipher,x509_issuer,x509_subject)

values

('user3'

,'localhost'

,password(

'123456'),

'','',

'');## 第二種方式:建立明文密碼之後進行修改

update mysql.

user

set password=password(

'123456'

)where

user

='user3'

;flush privileges

;

注意用insert方式建立使用者後必須重新整理許可權,這是為了告訴伺服器重讀授權表。否則,只有重啟伺服器後更改方會被注意到。

mysql5.7密碼list中password變了為authentication_string

create

user

'username'@'host' identified by 'password'

## 刪除使用者

drop

user user2;

drop

user user2@localhost

;## 撤銷許可權

revoke

allon*.

*from

'user2'

@'localhost'

;

## 修改當前登入使用者密碼

set password = password(

'newpwd');

## 修改指定使用者密碼

set password for username@host

=password(

'newpwd');

## 使用grant修改密碼

grant

allon*.

*to user2@localhost identified by

'newpwd'

;## 直接update mysql.user表,然後flush privileges;(不推薦)

update mysql.

user

set password=password(

'newpwd'

)where host=

'host'

anduser

='username'

flush privileges

;## 使用mysqladmin

mysqladmin -uusername -poldpwd password newpwd

Mysql建立 刪除使用者

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 mysql u root p 密碼 mysql insert into mysql.user host,user,password values localhost tes...

Mysql建立 刪除使用者

建立使用者 mysql insert into mysql.user host,user,password values localhost test password 1234 這樣就建立了乙個名為 test 密碼為 1234 的使用者。注意 此處的 localhost 是指該使用者只能在本地登入...

Mysql建立 刪除使用者

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 mysql u root p 密碼 mysql insert into mysql.user host,user,password values localhost tes...