天天看點

Mysql操作(待續)

前提是需要開啟表的binlog日志

log-bin=test-bin

一、檢視binlog的起始位置和結束位置,Pos是起始,End_log_pos是結束

[root@slave mysql]# mysql -uroot -e "use test;show binlog events"

+-----------------+-----+-------------+-----------+-------------+-------------------------------------------------------------+

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

| test-bin.000001 | 4 | Format_desc | 134 | 245 | Server ver: 5.5.52-MariaDB, Binlog ver: 4 |

| test-bin.000001 | 245 | Query | 1 | 360 | use <code>test</code>; create table t44(id int not null,name char(20)) |

| test-bin.000001 | 360 | Query | 134 | 465 | use <code>test</code>; DROP TABLE <code>t44</code> / generated by server / |

| test-bin.000001 | 465 | Stop | 134 | 484 | |

[root@master mysql]# mysqlbinlog test-bin.000002

Mysql操作(待續)

以上這個截圖操作是根據binlog位置進行資料恢複

參數說明:

-B:指定資料庫

-F:重新整理日志

-R:備份存儲過程等

-x:鎖表

--master-data:在備份語句裡添加CHANGE MASTER語句以及binlog檔案及位置點資訊

三、查詢連接配接的IP幾多

select SUBSTRING_INDEX(host,':',1) as ip , count(*) from information_schema.processlist group by ip;

四、查詢鎖表情況

show status like 'Table%';

Mysql操作(待續)

Table_locks_immediate表示立即釋放表鎖數,Table_locks_waited表示需要等待的表鎖數,

如果Table_locks_immediate / Table_locks_waited &gt; 5000,最好采用InnoDB引擎,

因為InnoDB是行鎖而MyISAM是表鎖,對于高并發寫入的應用InnoDB效果會好些。

示例中的伺服器Table_locks_immediate / Table_locks_waited = 235,MyISAM就足夠了。

五、關于報錯

Mysql操作(待續)

這個的報錯是權限的問題,因為互為主備的存放的binlog數不同,我直接從另一個庫那裡傳過去,沒改權限導緻。

Mysql操作(待續)

     本文轉自wsw26 51CTO部落格,原文連結:http://blog.51cto.com/wsw26/2051731,如需轉載請自行聯系原作者

繼續閱讀