mysql資料授權常用練習題

2021-09-22 21:29:26 字數 4076 閱讀 7361

在資料庫伺服器192.168.4.50上做如下:

1、修改資料庫管理員從本機登入的密碼為plj666, 資料庫管理員使用新密碼從本機連線資料庫伺服器==

mysql> set global  validate_password_policy=low;     //設定長度

mysql> set global validate_password_length=6;

mysql> alter user user() identified by "plj666"; //修改密碼

2、檢視當前登陸資料庫伺服器的使用者是誰?

mysql> select user();
3、檢視當前登陸資料庫伺服器使用者的許可權?

mysql> select user,host from mysql.user;
4、檢視當前資料庫伺服器有哪些授權使用者?

mysql> show grants;

mysql> select user,host from mysql.user;

5、授權管理員使用者root可以在網路中的192.168.4.254主機登入,對所有庫和表有完全許可權且有授權的許可權 登陸密碼tarena

mysql> grant all on *.* to root@"192.168.4.254"  identified by "tarena";

mysql> show grants for root@"192.168.4.254";

6、不允許資料庫管理員root在資料庫伺服器本機登入。

mysql>delete from mysql.user where  user="root" and host="localhost"; flush privileges;
7、授權yaya108使用者可以從網路中的任意主機訪問資料庫伺服器,僅對對userdb庫下的user表有檢視記錄、更新name欄位的許可權 , 登入密碼userweb888。

mysql> grant select,update(name) on userdb.user to yaya108@"%" identified by "userweb888";
8、驗證以上授權是否成功

]# mysql -h192.168.4.50 -uyaya108 -p"userweb888"

mysql>

9、yaya108使用者修改自己的登陸密碼為123456,並驗證能否使用新密碼登陸

]# mysql -h192.168.4.50 -uyaya108 -p"userweb888"

mysql> alter user user() identified by "123456";

mysql> exit

]# mysql -h192.168.4.50 -uyaya108 -p"123456"

10、 資料庫管理員修改授權使用者yaya的登入密碼為654321,讓授權使用者yaya 使用新密碼登陸資料庫伺服器。

]# mysql -uroot -pplj666       //管理員登入

mysql> set password for yaya108@"%"=password("654321");

mysql> exit

]# mysql -uyaya108 -p654321

11、撤銷授權使用者yaya108 的所有授權並 使其不再能使用此使用者連線資料庫伺服器。

mysql> revoke all on userdb.user from yaya108@"%";

mysql> drop user yaya108@"%";

12、授權webadmin使用者可以從網路中的所有主機登入,對bbsdb庫擁有完全許可權,且有授權許可權,登入密碼為 123456

mysql> create database bbsdb;           //創庫

mysql> grant all on bbsdb.* to webadmin@"%" identified by "123456" with grant option; //授權

mysql> grant insert on mysql.* to webadmin@"%"

]# mysql -h192.168.4.50 -uwebadmin -p123456 //驗證登入

mysql> show grants; //使用者檢視自己的許可權

13、在客戶端使用授權使用者webadmin登入,把自己的許可權授權給userone使用者 , 登入密碼是 123456

]# mysql -h192.168.4.50 -uwebadmin -p123456

mysql> grant all on bbsdb.* to userone@"%" identified by "123456" with grant option;

mysql> grant insert on mysql.* to userone@"%";

14、撤銷webadmin使用者的授權許可權。

mysql> revoke grant option on *.* from webadmin@"%";
15、授權資料庫管理員可以在本機連線資料庫服務。

mysql> grant all on *.* to root@"localhost" identified by "123456" with grant option
16、不允許主機192.168.4.254使用root使用者連線資料庫伺服器192.168.4.50

mysql> delete from mysql.user where user="root" and host="192.168.4.254";flush privileges;
補充:

授權命令----grant 許可權列表 on 資料庫名 to 使用者名稱@「客戶端位址」 identified by 」密碼「 [with grant option];

—當庫名.表名 為 . 時,匹配所有庫所有表—授權設定存放在------mysql.user庫的表

列:

mysql> grant all on *.* to mydb@"%" identified by "123456" with grant option;
許可權列表:

----all-----匹配所有許可權

—select,update,insert、、、、、

----select,update(欄位1,、、、欄位n)

檢視使用者授權

—show grants; //使用者檢視自己的許可權

----show grants for 使用者名稱@「客戶端位址」; //管理員檢視其他使用者的許可權

重設使用者密碼:

授權使用者連線後修改密碼----- set password=password(「新密碼」);

撤銷授權----把新增使用者的訪問許可權刪除

revoke 許可權列表 on 庫名.表名 from 使用者名稱@「客戶端位址」;

刪除新增的使用者

mysql>drop user 使用者名稱@「客戶端位址」;

.授權庫mysql:記錄授權資訊的庫,使用不同的表記錄授權資訊

user表 ----儲存已有的授權使用者

desc mysql.user; select user,host from mysql.user;

db表 -----儲存授權使用者對庫的訪問許可權

tables_priv表-----儲存 授權使用者對錶的訪問許可權

columns_priv表------儲存授權使用者對表字段的訪問許可權

MySQL查詢練習題

在挑戰實驗1中構建的成績管理系統中,物理老師想要找出分數最高的同學進行表揚,請你找出這個同學並把他的資訊 id 姓名 性別 輸出到路徑 tmp 下的 physics.txt檔案中。同時 tom 的化學成績有異議,需要在原來的基礎上加3分,請更新 tom 的化學成績。wget資料庫 gradesyst...

mysql 簡單練習題

create table student id int,name varchar 20 chinese float,english float,math float insert into student id,name,chinese,english,math values 1,張小明 89,78...

MySQL函式 練習題

1.使用數學函式進行如下運算 1 計算18除以5的餘數。2 將弧度值pi 4轉換為角度值。3 計算9的4次方值 4 保留浮點值3.14159小數點後面2位。2.使用字串函式進行如下運算。1 分別計算字串 hello world 和 university 的長度。2 從字串 nice to meet ...