其實摸了這么久加固真覺得就mysql和iptables難點其他沒什么,嗚嗚嗚嗚嗚……但我這個渣渣學攻擊快學崩掉遼(emo),因為講真網路安全是很多東西組合在一塊得看你怎么學了
一.安裝Mysql
yum -y install mysql mysql-server
二.開啟mysql服務
service mysqld start

三.查看mysql服務的狀態
service mysqld status
![]()
(正常來說應該是3306我也不知道怎么變成3106了
)
☆☆☆☆☆
剛裝好的mysql一般無密碼可直接進入
mysql -u root -p
設定密碼并進入
mysqladmin -u root password '設定你的密碼'
mysql -u root -p

☆☆☆☆☆
四.Mysql基礎命令!!!(在mysql里面執行命令“;”很重要!)
1.查看資料庫
show databases;
2.使用某個資料庫
use +資料庫名;
3.查看表(前提是要先進入資料庫)
show tables;

4.查看表結構
describe +表名;

5. 洗掉某個資料庫
drop database +資料庫名;

6.新建用戶
create user '用戶名'@'localhost' identified by '密碼';
![]()
7.查看用戶表
select user,host from mysql.user;

8.洗掉用戶
drop user '用戶名'@'localhost';

9.重繪權限(例如你改了某個用戶密碼或者給予了某些權限可以重繪)
flush privileges;

10.顯示表中的所有記錄(表在庫中)
select * from +表名;

五.例題
1.對忘記mysql資料庫root管理員密碼進行重置操作
vim /etc/my.cnf
#在[mysqld]下面加入
skip-grant-tables(跳過權限檢查啟動)
#然后
service mysqld restart
mysql –u root –p
use mysql;
update user set password=password(“新密碼”) where user=”root”;
flush privileges; #(重繪權限)
![]()



2.賦予user1用戶對資料庫所有表只有select,insert,delete,update權限
mysql –u root -p
grant select,insert,delete,update on 資料庫名.* to user1@’locaolhost’;
show grants for ‘user1’@’localhost’;

3.禁用LOCAL INFILE命令防止非授權用戶訪問本地檔案
vi /etc/my.cnf
#在[mysqld]下面加入
set-variable=local-infile=0

4.為防止資料庫操作資訊泄露,請禁止使用mysql命令列歷史記錄
rm –f $HOME/.mysql_history
ln –s /dev/null $HOME/.mysql_history
5.為分析資料庫運行程序中的一些例外活動,請開啟mysql二進制日志
vi /etc/my.cnf
#在[mysqld]下面加入
log-bin=mysql-bin
#然后
service mysqld restart
mysql -u root -p
show variables like ‘log_bin’;
![]()



6.使用mysql內置MD5加密函式加密用戶user1的密碼為(P@ssw0rd1!),并查看用戶user1密碼
vim /etc/my.cnf
#在[mysqld]下面添加
skip-grant-tables
#然后
service mysqld restart
mysql –u root –p
use mysql;
update user set password=md5(password) where user=”user1”;
select password from user where user=’uesr1’;
![]()



7.以普通賬戶mysql安全運行mysql,禁止mysql以管理員賬號權限運行
vi /etc/my.cnf
#在[mysqld]下面加入
user=mysql
![]()

8.改變默認mysql管理員用戶為:SuperRoot
mysql –u root –p
use mysql;
update user set user=”SuperRoot” where user=”root”;

9.洗掉默認資料庫test,然后使用show databases;命令查看當前的資料庫資訊
mysql –u root –p
show databases;
drop database test;
select database();

10.限制一般用戶瀏覽其他用戶資料庫,對mysqld的啟動項進行加固
vim /etc/my.cnf
#在[mysqld]下面添加
skip-show-database
![]()

11.創建一個新的mysql資料庫用戶(grant陳述句)
mysql -u root -p
use mysql;
grant all on *.* to '用戶名'@'localhost' identified by '密碼';

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/390573.html
標籤:其他
