1. 程式人生 > >mariadb資料庫的使用者和許可權

mariadb資料庫的使用者和許可權

實驗--使用者

use mysql

show tables;

desc uesr;                                #存放mysql的使用者

select host,user,password from user;

create user [email protected]'%' identified by '123465'; 

create user [email protected]'192.168.100.2' identified by '123465';

create user [email protected]'192.168.100.0/255.255.255.0' identified by '123465';

                                           #建立遠端連線使用者(%在紅帽7裡只表示所有遠端連線的使用者)

 yum istall mariadb 客戶端安裝這個

mysql -h 192.168.100.1 -u qin -p 遠端連線

create user [email protected]'localhost' identified by '123456';    #建立本地登入使用者(企業的本地登入使用的較多)

drop user [email protected]'%';                                     #刪除使用者

show privileges;                                       #檢視許可權列表

grant select on scott.* to [email protected]'localhost';

授權  許可權      庫   表    那個使用者   

flush privileges;                                      #重新整理一下許可權表

select * from emp;

drop table emp;                                        #使用 [email protected]

'localhost登入,無權刪除

show grants for [email protected]'localhost';                       #檢視使用者許可權

revoke select on scott.* from [email protected]'localhost';         #收回許可權

grant all on *.* to [email protected]'localhost' identified by '123456'; 授權  建使用者  設密碼一起建立

修改密碼

第一種:mysqladmin -u root -p password 'redhat';       #修改密碼

第二種:update user set password=password('123456') where user='root' and host='localhost'; 

第三種:set password=password('redhat');

        set password for [email protected]'localhost'=password('redhat');   #第二種和第三種是在mysql庫下修改的


實驗--破解mysql密碼


第一種:

停止mariadb的服務

在/etc/my.cnf 裡新增一行skip-grant-tables 跳過許可權

重啟服務

mysql -u root -p 直接回車 不用輸入密碼

use mysql

select host,user,password from user;

update user set password=password('123456') where uesr='root' and host='localhost';

刪除skip-grant-tables,重啟服務,登入即可

第二種方式:

mysql_safe --skip-grant-tables  再開啟一個視窗

直接mysql 進入

修改密碼就可以了

重啟服務即可

實驗--安全指令碼

mariadb提高安全性有一種安全的指令碼(資料庫安裝完之後,先執行這個)

mysql_secure_installation  然後一路‘y’即可  然後重啟服務即可 

show databases;

沒有test庫  遠端的root就不能連了

不允許網路連線 :在配置檔案新增一行  skip-networking=1  加一行這個,就不允許遠端連線mysql資料庫了

netstart -antulp | grep mysql

mysql workbench