DAY5-MySQL日誌管理

來源:互聯網
上載者:User

標籤:磁碟   終端   位置   purge   檔案   引擎   show   狀態   審計   

 

 

記錄檔


錯誤記錄檔 --log-error error-log=/data/mysql/mysql3306/error.log
常規日誌 --general_log=/data/mysql/mysql3306/general_log
慢查詢日誌 --slow_query-log=/data/mysql/mysql3306/slow_log       分析工具:mysqldumpslow/pt-query-digest 
二進位日誌 --log-bin=/data/mysql/mysql3306/mysql-bin       (保留7天日誌 expire-logs-days = 7)    分析工具: mysqlbinlog/binlog2sql
審計日誌 (官方收費外掛程式) --audit_log --audit_log_file audit.log

 

 

二進位日誌

33DDL DML DCL DQL

什麼時候進行切換:
1、flush logs; (如果卡著不動,有可能有大事務沒結束,一個事務只能寫到一個binlog裡面)
2、超過日誌設定 max_binlog_size
3、資料庫重啟

二進位日誌記錄的格式:
binlog_format=row
statement: 記錄執行的SQL語句 (過去式,主從版本不統一,遷移,升級的過度狀態)
insert into t1 (id,c1) values (1,uuid()); 主從不一致。
row:記錄更改前後的資料(生產用)
mixed:(不要用)

查看binlog:
show binary logs;
show master status; 5.7 gtid: select @@server_uuid; 查到自己的server還是從別的地方拿到執行的事務。
show binlog events in ‘mysql-bin.000001‘;
MySQL的二進位是以‘事件(event)為單位儲存到日誌中,一個insert,update。。。有多個事件組成。
event:begin,table_map,x_event,commit;
position:位元組位移量(位置)show master status顯示的position就是日誌的大小。

查看二進位日誌:
無法用文本查看
日誌以緊湊二進位格式儲存,以事件組合
使用mysqlbinlog查看
mysqlbinlog -v --base64-output=decode-rows mysql-bin.000001 > t.log

刪除二進位日誌:
基於時間刪除
set global expire_logs_days=7;
purge binary logs before now()-interval 3 day3;
基於檔案名稱刪除
purge binary logs to ‘mysql-bin.000010‘;


審計日誌:
audit——log_policy選項設定
預設all

記錄檔產生一個伺服器活動審計記錄:
內容包括,在系統生髮生的錯誤記錄,
客戶機串連和斷開的時間,
串連期間執行的操作,
訪問的資料庫和表。

 

MySQL常用命令

help show; 協助資訊
pager more; 分頁查看
pager less; 上下查看
pager cat; 返回

 

information_schema:
中央資訊庫,磁碟找不到,只能select。

查看schema下面的表的儲存引擎:
select table_name,engine from information_schema.tables where tables_schema=‘test‘
查看錶的字元集:
select character_set_name.collation_name from information_schema.colltions where is_default=‘Yes‘;
查看每個庫下面有多少長表:
select table_schema , count(*) from information_schema.tables group by table_schema;

庫改名:
1、create database newdata;
rename olddata.t1 to newdata.t1;
2、select concat("rename table olddata.",table_name," to new.",table_name," ;" from information_schema.tables where table_schema=‘olddata‘ into outfile ‘/tmp/rename.sql‘;
source /tmp/rename.sql;
3、終端 mysql -e " " > rename.sql

統計庫大小:
單位M : select sum(data_length+index_length)/1024/1024 from information_schema.tables where table_schema=‘test‘;
統計每張表的大小:
單位M :select table_name,sum(data_length+index_length)/1024/1024 from information_schema.tables where table_schema=‘test‘ group by table_name;

show核心語句
show open tables; 查看當然開啟的表
show table status like ‘‘; 不建議高並發使用
show columns from tb;
show full columns from tb;
show databases like "t%";
show columns from db where ‘Default‘ is null;
show character set ;
show collation;

show global variables ; 全域global
show variables; 當前session

show @@ xxx; 全域

show @ xxx;   session

 

 

練習指令碼:
1、error如果有變更,將變更列印出來:
備份error,diff備份檔案和線上檔案

 

 

 


 

DAY5-MySQL日誌管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.