MySQL 的新增使用者 刪除使用者 授權

2021-08-26 05:52:32 字數 3296 閱讀 8740

3、增加使用者:

(注意:和上面不同,下面的因為是mysql環境中的命令,所以後面都帶乙個分號作為命令結束符) 

格式:grant select on 資料庫.* to 使用者名稱@登入主機 identified by 「密碼」

第一種:

增加乙個使用者test1密碼為abc,讓他可以在任何主機上登入,並對所有資料庫有查詢、插入、修改、刪除的許可權。首先用以root使用者連入mysql,然後鍵入以下命令: 

grant select,insert,update,delete on *.* to test1@「%」 identified by 「abc」;

但增加的使用者是十分危險的,你想如某個人知道test1的密碼,那麼他就可以在internet上的任何一台電腦上登入你的mysql資料庫並對你的資料可以為所欲為了,解決辦法見例第二種: 

第一種:增加乙個使用者test2密碼為abc,讓他只可以在localhost上登入,並可以對資料庫mydb進行查詢、插入、修改、刪除的操作(localhost指本地主機,即mysql資料庫所在的那台主機),這樣使用者即使用知道test2的密碼,他也無法從internet上直接訪問數

mysql> grant select,insert,update,delete on book.* to test2@localhost identified by "abc";

如果你不想test2有密碼,可以再打乙個命令將密碼消掉。 

mysql> grant select,insert,update,delete on book.* to test2@localhost identified by "";

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼(注意每行後邊都跟個;表示乙個命令語句結束):

1.新建使用者

1.1 登入mysql:

@>mysql -u root -p

@>密碼

1.2 建立使用者:

mysql> insert into mysql.user(host,user,password) values("localhost","test",password("1234"));

這樣就建立了乙個名為:test 密碼為:1234 的使用者。

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

1.3 然後登入一下:

mysql>exit;

@>mysql -u test -p

@>輸入密碼

mysql>登入成功

2.為使用者授權

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

2.1 登入mysql(有root許可權),這裡以root身份登入:

@>mysql -u root -p

@>密碼

2.2 首先為使用者建立乙個資料庫(testdb):

mysql>create database testdb;

2.3 授權test使用者擁有testdb資料庫的所有許可權(某個資料庫的所有許可權):

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

mysql>flush privileges;//重新整理系統許可權表

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

2.4 如果想指定部分許可權給一使用者,可以這樣來寫:

mysql>grant select,update on testdb.* to test@localhost identified by '1234';

mysql>flush privileges; //重新整理系統許可權表

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

mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

//test使用者對所有資料庫都有select,delete,update,create,drop 許可權。

//@"%" 表示對所有非本地主機授權,不包括localhost。(localhost位址設為127.0.0.1,如果設為真實的本地位址,不知道是否可以,沒有驗證。)

//對localhost授權:加上一句grant all privileges on testdb.* to test@localhost identified by '1234';即可。

3. 刪除使用者

@>mysql -u root -p

@>密碼

mysql>delete from user where user='test' and host='localhost';

mysql>flush privileges;

mysql>drop database testdb; //刪除使用者的資料庫

刪除賬戶及許可權:>drop user 使用者名稱@'%';

>drop user 使用者名稱@ localhost; 

4. 修改指定使用者密碼

@>mysql -u root -p

@>密碼

mysql>update mysql.user set password=password('新密碼') where user="test" and host="localhost";

mysql>flush privileges;

5. 列出所有資料庫

mysql>show database;

6. 切換資料庫

mysql>use '資料庫名';

7. 列出所有表

mysql>show tables;

8. 顯示資料表結構

mysql>describe 表名;

9. 刪除資料庫和資料表

mysql>drop database 資料庫名;

mysql>drop table 資料表名;

mysql新增使用者 Mysql新增使用者與授權

1 本地環境 centos linux release 7.5.1804 core 2 以root使用者登入mysql mysql uroot proot 3 切換到mysql資料庫 use mysql 4 新增使用者 只允許指定ip連線 create user 新使用者名稱 localhost i...

mysql 新增使用者 mysql建立使用者與授權

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

MySQL使用者管理 新增使用者 授權 刪除使用者

新增使用者 以root使用者登入資料庫,執行以下命令 create user zhangsan identified by zhangsan 上面的命令建立了使用者zhangsan,密碼是zhangsan。在mysql.user表裡可以檢視到新增使用者的資訊 授權命令格式 grant privile...