您好,登錄后才能下訂單哦!
MySQL添加用戶、刪除用戶與授權(quán)
MySql中添加用戶,新建數(shù)據(jù)庫,用戶授權(quán),刪除用戶,修改密碼(注意每行后邊都跟個;表示一個命令語句結(jié)束):
1.新建用戶
1.1 登錄MYSQL:
@>mysql -u root -p
@>密碼
1.2 創(chuàng)建用戶:
mysql> insert into mysql.user(Host,User,Password) values(" localhost","test",password("1234"));
這樣就創(chuàng)建了一個名為:test 密碼為:1234 的用戶。
注意:此處的"localhost",是指該用戶只能在本地登錄,不能在另外一臺機(jī)器上遠(yuǎn)程登錄。如果想遠(yuǎn)程登錄的話,將"localhost"改為"%",表示在任何一臺電腦上都可以登錄。也可以指定某臺機(jī)器可以遠(yuǎn)程登錄。
1.3 然后登錄一下:
mysql>exit;
@>mysql -u test -p
@>輸入密碼
mysql>登錄成功
2.為用戶授權(quán)
授權(quán)格式:grant 權(quán)限 on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī) identified by "密碼";
2.1 登錄MYSQL(有ROOT權(quán)限),這里以ROOT身份登錄:
@>mysql -u root -p
@>密碼
2.2 首先為用戶創(chuàng)建一個數(shù)據(jù)庫(testDB):
mysql>create database testDB;
2.3 授權(quán)test用戶擁有 testDB數(shù)據(jù)庫的所有權(quán)限(某個數(shù)據(jù)庫的所有權(quán)限):
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';
mysql>flush privileges;//刷新系統(tǒng)權(quán)限表
格式:grant 權(quán)限 on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī) identified by "密碼";
2.4 如果想指定 部分權(quán)限給一用戶,可以這樣來寫:
mysql>grant select,update on testDB.* to test@localhost identified by '1234';
mysql>flush privileges; //刷新系統(tǒng)權(quán)限表
2.5 授權(quán)test用戶擁有 所有數(shù)據(jù)庫的某些權(quán)限:
mysql>grant select,delete,update,create,drop on . to test @"%" identified by "1234";
//test用戶對所有數(shù)據(jù)庫都有select,delete,update,create,drop 權(quán)限。
// @"%" 表示對所有非本地主機(jī)授權(quán),不包括localhost。(localhost地址設(shè)為127.0.0.1,如果設(shè)為真實(shí)的本地地址,不知道是否可以,沒有驗證。)
//對localhost授權(quán):加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。
刪除用戶
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User='test' and Host='localhost';
mysql>flush privileges;
mysql>drop database testDB; //刪除用戶的數(shù)據(jù)庫
刪除賬戶及權(quán)限:>drop user 用戶名@'%';
drop user 用戶名@ localhost;
修改指定用戶密碼
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
mysql>flush privileges;
mysql>show database;
mysql>use '數(shù)據(jù)庫名';
mysql>show tables;
mysql>describe 表名;
mysql>drop database 數(shù)據(jù)庫名;
mysql>drop table 數(shù)據(jù)表名;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。