{"rsdb":{"rid":"156500","subhead":"","postdate":"0","aid":"117468","fid":"57","uid":"1","topic":"1","content":"

\u5047\u5982\u67d0\u4e2a\u6570\u636e\u5e93\u88ab\u4eba\u5220\u9664\u4e86\uff0c\u4f46\u662f\u62e5\u6709\u6570\u636e\u5e93\u6743\u9650\u7684\u4eba\u5f88\u591a\uff0c\u8fd9\u6837\u6709\u5fc5\u8981\u8bb0\u5f55\u4e0b\u6bcf\u4e2a\u4eba\u7684\u64cd\u4f5c\u7eaa\u5f8b\u3002\u4f46\u662f\u5982\u679c\u5f00\u542f\u4e86<\/span>general log<\/span>\u7684\u8bdd\uff0c\u65e5\u5fd7\u53c8\u975e\u5e38\u5927\u3002<\/span><\/p>

\u4e0b\u9762\u7684\u4f7f\u7528<\/span>init_connect<\/span>\u7684\u65b9\u6cd5\u8fd8\u4e0d\u9519\u3002<\/span><\/p>

\u767b\u5f55\u8fdb<\/span><\/strong>mysql<\/span><\/strong>\uff0c\u521b\u5efa\u4e00\u4e2a\u65e5\u5fd7\u8868<\/span><\/strong><\/p>

> create database accesslog;<\/span><\/p>

> use accesslog;<\/span><\/p>

> CREATE TABLE `accesslog` (`id` int(11) primary key auto_increment,`user` char(100),`matchname` varchar(30));<\/span><\/p>

\u70ed\u914d\u7f6e\u751f\u6548<\/span><\/p>

> set global init_connect='insert into accesslog.accesslog values (connection_id(),user(),now());'<\/span><\/p>

\u7136\u540e\uff0c<\/span>vi \/etc\/my.cnf <\/span><\/p>

\u5728<\/span>[mysqld]<\/span>\u6dfb\u52a0<\/span><\/p>

init_connect='insert into accesslog.accesslog values (connection_id(),user(),now());'<\/span><\/p>

\u5c06\u914d\u7f6e\u6301\u4e45\u5316\u5230\u6587\u4ef6\u3002<\/span><\/p>

# <\/span>\u6ce8\u610f\uff1a<\/span><\/p>

\u9700\u8981\u7ed9\u666e\u901a\u7528\u6237\u52a0\u4e0a\u64cd\u4f5c<\/span>insert<\/span>\u64cd\u4f5c<\/span>accesslog.*<\/span>\u7684\u6743\u9650<\/span>,<\/span>\u5982\uff1a<\/span>grant INSERT on accesslog.* to'abc'@'%';<\/span><\/p>

\u7136\u540e\uff0c\u521b\u5efa\u51e0\u4e2a\u666e\u901a\u7ea7\u522b\u6743\u9650\u7684\u8d26\u53f7\uff08\u9700\u8981\u7ed9\u666e\u901a\u7528\u6237\u52a0\u4e0a\u64cd\u4f5c<\/span>insert<\/span>\u64cd\u4f5c<\/span>accesslog.*<\/span>\u7684\u6743\u9650\uff09\uff0c\u7528\u8fd9\u4e9b\u4f4e\u7ea7\u522b\u8d26\u6237\u8fdb\u53bb\u64cd\u4f5c\u4e0b\u6570\u636e\u5e93\u6216\u8005\u6570\u636e\u8868\u3002<\/span><\/p>

root<\/span><\/strong>\u7528\u6237\u8fdb\u53bb\u67e5\u770b\u64cd\u8bb0\u5f55\uff1a<\/span><\/strong><\/p>

> select * from accesslog.accesslog; ?<\/span>\u7c7b\u4f3c\u5982\u4e0b\uff1a<\/span><\/p>

\u5047\u5982\u6211\u4eec\u73b0\u5728\u53d1\u73b0\u6570\u636e\u5e93\u88ab\u4eba\u4e3a\u8bef\u5220\u4e86\u6570\u636e\uff0c\u5219\u53ef\u4ece<\/span>binlog<\/span>\u4e2d\u770b\u5230\u76f8\u5173\u7684\u4e8b\u52a1\u7684<\/span>thread_id<\/span>\uff0c\u5982\u4e0b\u56fe\u7684\u7ea2\u8272\u90e8\u5206<\/span>38<\/span>\u3002<\/span><\/p>

\u518d\u7ed3\u5408<\/span>accesslog.accesslog<\/span>\u91cc\u9762\u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u770b\u5230\u662f\u4e0b\u56fe\u8fd9\u4e2a\u65f6\u95f4\u70b9\u767b\u5f55\u7684\u8d26\u6237\u64cd\u4f5c\u7684\u3002\u8fd9\u6837\u5c31\u6709\u636e\u53ef\u67e5\u3002<\/span><\/p>","orderid":"0","title":"MySQL audit\u8bbf\u95ee\u65e5\u5fd7\u8bb0\u5f55","smalltitle":"","mid":"0","fname":"\u6570\u636e\u5e93\u7f16\u7a0b","special_id":"0","bak_id":"0","info":"0","hits":"2036","pages":"1","comments":"0","posttime":"2017-02-21 08:16:00","list":"1487636160","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"MySQL<\/A> audit<\/A> \u8bbf\u95ee<\/A> \u65e5\u5fd7<\/A> \u8bb0\u5f55<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.31","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"MySQL audit\u8bbf\u95ee\u65e5\u5fd7\u8bb0\u5f55","lastview":"1713606233","digg_num":"2810","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}