MySql 5.7中添加使用者,建立資料庫,使用者授權,刪除使用者,修改密碼

來源:互聯網
上載者:User

標籤:localhost   block   使用者密碼   ica   base   添加   使用者建立   登入   系統許可權   

1、建立使用者
建立test使用者,密碼是1234。

mysql -u root -p
CREATE USER “test”@”localhost” IDENTIFIED BY “1234”; #本地登入
CREATE USER “test”@”%” IDENTIFIED BY “1234”; #遠程登入
quit
mysql -utest -p #測試是否建立成功

2、為使用者授權

a.授權格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by “密碼”; 

b.登入MYSQL,這裡以ROOT身份登入:

mysql -u root -p

c.為使用者建立一個資料庫(testDB):

create database testDB;
create database testDB default charset utf8 collate utf8_general_ci;

d.授權test使用者擁有testDB資料庫的所有許可權:

grant all privileges on testDB.* to “test”@”localhost” identified by “1234”;
flush privileges; #重新整理系統許可權表

e.指定部分許可權給使用者:

grant select,update on testDB.* to “test”@”localhost” identified by “1234”;
flush privileges; #重新整理系統許可權表

f.授權test使用者擁有所有資料庫的某些許可權:  

grant select,delete,update,create,drop on . to [email protected]”%” identified by “1234”; #”%” 表示對所有非本地主機授權,不包括localhost

3、刪除使用者

mysql -u root -p
Delete FROM mysql.user Where User=”test” and Host=”localhost”;
flush privileges;
drop database testDB;

刪除賬戶及許可權:

drop user 使用者名稱@’%’;
drop user 使用者名稱@ localhost;

4、修改指定使用者密碼

mysql -u root -p
update mysql.user set authentication_string=password(“新密碼”) where User=”test” and Host=”localhost”;
flush privileges;

    

MySql 5.7中添加使用者,建立資料庫,使用者授權,刪除使用者,修改密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.