{"id":8272,"date":"2021-10-25T15:44:31","date_gmt":"2021-10-25T07:44:31","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=8272"},"modified":"2022-01-18T15:19:31","modified_gmt":"2022-01-18T07:19:31","slug":"gbase-8a%e6%95%b0%e6%8d%ae%e5%ba%93%e5%b0%86%e5%ae%a1%e8%ae%a1%e6%97%a5%e5%bf%97%e6%96%87%e4%bb%b6%e5%8a%a0%e8%bd%bd%e5%88%b0%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e4%b8%80%e4%b8%aa%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/8272","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u6570\u636e\u5e93\u5c06\u5ba1\u8ba1\u65e5\u5fd7\u6587\u4ef6\u52a0\u8f7d\u5230\u6570\u636e\u5e93\u7684\u4e00\u4e2a\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u672c\u6587\u4ecb\u7ecd\u4e00\u79cd\uff0c\u4ece\u6587\u672c\u683c\u5f0f\u7684\u5ba1\u8ba1\u65e5\u5fd7\uff0c\u901a\u8fc7\u66ff\u6362\u81ea\u5b9a\u4e49\u5b57\u6bb5\u548c\u884c\u5206\u9694\u7b26\uff0c\u52a0\u8f7d\u5230GBase 8a\u6570\u636e\u5e93\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u76ee\u5f55\u5bfc\u822a<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2afd7596c7b\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2afd7596c7b\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%8F%82%E8%80%83\" >\u53c2\u8003<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%AE%A1%E8%AE%A1%E6%97%A5%E5%BF%97%E8%BE%93%E5%87%BA%E6%A0%BC%E5%BC%8F\" >\u5ba1\u8ba1\u65e5\u5fd7\u8f93\u51fa\u683c\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E6%97%A5%E5%BF%97%E6%96%87%E4%BB%B6\" >\u65e5\u5fd7\u6587\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E6%97%A5%E5%BF%97%E6%A0%B7%E4%BE%8B\" >\u65e5\u5fd7\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#SHELL_%E5%A4%84%E7%90%86%E6%96%B9%E6%A1%88\" >SHELL \u5904\u7406\u65b9\u6848<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%A4%84%E7%90%86%E8%BF%87%E7%A8%8B\" >\u5904\u7406\u8fc7\u7a0b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E8%A1%A8\" >\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%8A%A0%E8%BD%BDSQL\" >\u52a0\u8f7dSQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%AE%8C%E6%95%B4%E8%84%9A%E6%9C%AC\" >\u5b8c\u6574\u811a\u672c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E8%BF%90%E8%A1%8C%E6%A0%B7%E4%BE%8B\" >\u8fd0\u884c\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9%E5%92%8C%E9%99%90%E5%88%B6\" >\u6ce8\u610f\u4e8b\u9879\u548c\u9650\u5236<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#Python%E5%A4%84%E7%90%86%E6%96%B9%E6%A1%88%E5%BB%BA%E8%AE%AE\" >Python\u5904\u7406\u65b9\u6848(\u5efa\u8bae)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E8%84%9A%E6%9C%AC\" >\u811a\u672c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%BB%BA%E8%A1%A8%E8%AF%AD%E5%8F%A5\" >\u5efa\u8868\u8bed\u53e5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.gbase8.cn\/en\/8272\/#%E5%8A%A0%E8%BD%BD%E6%96%B9%E5%BC%8F\" >\u52a0\u8f7d\u65b9\u5f0f<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83\"><\/span>\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.gbase8.cn\/168\">GBase 8a \u96c6\u7fa4\u5ba1\u8ba1\u65e5\u5fd7audit_log\u653b\u7565\u548c\u4f7f\u7528\u65b9\u6cd5<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%A1%E8%AE%A1%E6%97%A5%E5%BF%97%E8%BE%93%E5%87%BA%E6%A0%BC%E5%BC%8F\"><\/span>\u5ba1\u8ba1\u65e5\u5fd7\u8f93\u51fa\u683c\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u9ed8\u8ba4log_output='FILE'<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%97%A5%E5%BF%97%E6%96%87%E4%BB%B6\"><\/span>\u65e5\u5fd7\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>gcluster\/log\/gcluster\/gclusterd-audit.log<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%97%A5%E5%BF%97%E6%A0%B7%E4%BE%8B\"><\/span>\u65e5\u5fd7\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Threadid=5;\n# Taskid=80;\n# Time: 211025 13:28:58\n# End_time: 211025 13:29:00\n# User@Host: root&#91;root] @ localhost &#91;]\n# UID: 1\n# Query_time: 2.002046 Rows: 1\n# Tables: WRITE: ; READ: ; OTHER: ; ;\n# SET timestamp=1635139738;\n# Sql_text: select sleep(2);\n# Sql_type: DQL;\n# Sql_command: SELECT;\n# Status: SUCCESS;\n# Connect Type: CAPI;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SHELL_%E5%A4%84%E7%90%86%E6%96%B9%E6%A1%88\"><\/span>SHELL \u5904\u7406\u65b9\u6848<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%A4%84%E7%90%86%E8%BF%87%E7%A8%8B\"><\/span>\u5904\u7406\u8fc7\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>4.1\u3001\u5c06\u6240\u6709\u7684#\u5f00\u5934\u7684\u5b57\u6bb5\u90e8\u5206\uff0c\u66ff\u6362\u6210\u5b57\u6bb5\u5206\u9694\u7b26\u3002 \u6837\u4f8b\u662f^GBASE^<br>4.2\u3001\u5c06\u6700\u540e\u4e00\u4e2a\u5b57\u6bb5 # Connect Type: \u6700\u540e\u589e\u52a0\u884c\u5206\u9694\u7b26,\u6837\u4f8b\u662f ^GBASE_GBASE^<br>4.3 \u3001sed \u4ee3\u7801<br>cat gclusterd-audit.log |sed 's\/# Threadid=([0-9]+);\/\\1\/g' |sed 's\/# Taskid=([0-9]+);\/^GBASE^\\1\/g' |sed 's\/# Time: (.+)\/^GBASE^\\1\/g' |sed 's\/# End_time: (.+)\/^GBASE^\\1\/g' |sed 's\/# User@Host: (.<em>)\/^GBASE^\\1\/g' |sed 's\/# UID: ([0-9]+)\/^GBASE^\\1\/g' |sed 's\/# Query_time: (.<\/em>) Rows: ([0-9]+)\/^GBASE^\\1\\n^GBASE^\\2\/g' |sed 's\/# Tables: (.<em>);\/^GBASE^\\1\/g' |sed 's\/# SET timestamp=([0-9]<\/em>);\/\/g' |sed 's\/# # administrator command: ([0-9]<em>);\/\/g' |sed 's\/# Sql_text:(.<\/em>)\/^GBASE^\\1\/g' |sed 's\/# Sql_type:(.<em>);\/^GBASE^\\1\/g' |sed 's\/# Sql_command: (.<\/em>)\/^GBASE^\\1\/g' |sed 's\/# Status: (.<em>)\/^GBASE^\\1\/g' |sed 's\/# Connect Type: (.<\/em>);\/^GBASE^\\1^GBASE_GBASE^\/g' &gt; al.log<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%A1%A8\"><\/span>\u8868<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5b57\u6bb5\u540d\u53ef\u6839\u636e\u60c5\u51b5\uff0c\u505a\u4fee\u6539\uff0c\u6ce8\u610f\u5176\u4e2d\u7684Query_time ,\u662fdecimal\u5c0f\u6570\u7c7b\u578b<\/p>\n\n\n\n<p>\u8868\u540d\u5b57\u53ef\u4ee5\u968f\u610f\u4fee\u6539\uff0c\u540e\u9762\u52a0\u8f7d\u7684\u8868\u540d\u6ce8\u610f\u5bf9\u5e94\u4e0a\u5c31\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create table al(\nThreadid bigint,\nTaskid bigint,\nTime datetime,\nEnd_time datetime,\nUser_Host varchar(1000),\nUID bigint,\nQuery_time decimal(16,6),\nRows bigint,\nTables_list varchar(8000),\nSql_text varchar(8000),\nSql_command varchar(100),\nSql_type varchar(100),\nStatus varchar(100),\nconn_type varchar(100)\n);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8A%A0%E8%BD%BDSQL\"><\/span>\u52a0\u8f7dSQL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>load data infile 'sftp:\/\/gbase:gbase1234@10.0.2.201\/home\/gbase\/zxq\/audit_log\/al.log' into table al fields terminated by '^GBASE^' TABLE_FIELDS 'Threadid,Taskid,Time,End_time,User_Host,UID,Query_time,Rows,Tables_list,Sql_text,Sql_command,sql_type,Status,conn_type' lines terminated by '^GBASE_GBASE^' DATETIME FORMAT '%y%m%d %H:%i:%s';s\nQuery OK, 7 rows affected (Elapsed: 00:00:01.72)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%AE%8C%E6%95%B4%E8%84%9A%E6%9C%AC\"><\/span>\u5b8c\u6574\u811a\u672c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u6ce8\u610f\u91cc\u9762infile\u6570\u636e\u6e90\u7684\u90e8\u5206\uff0cIP,\u64cd\u4f5c\u7cfb\u7edf\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u8def\u5f84\u7b49\uff0c\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539\u811a\u672c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;gbase@rh6-1 audit_log]$ cat auditlog_load.sh\nlogfile=$1\nusername=$2\npassword=$3\ndbname=$4\ntablename=$5\n\ncat $logfile |sed 's\/# Threadid=\\(&#91;0-9]\\+\\);\/\\1\/g' |sed 's\/# Taskid=\\(&#91;0-9]\\+\\);\/^GBASE^\\1\/g' |sed 's\/# Time: \\(.\\+\\)\/^GBASE^\\1\/g' |sed 's\/# End_time: \\(.\\+\\)\/^GBASE^\\1\/g' |sed 's\/# User@Host: \\(.*\\)\/^GBASE^\\1\/g' |sed 's\/# UID: \\(&#91;0-9]\\+\\)\/^GBASE^\\1\/g' |sed 's\/# Query_time: \\(.*\\) Rows: \\(&#91;0-9]\\+\\)\/^GBASE^\\1\\n^GBASE^\\2\/g' |sed 's\/# Tables: \\(.*\\);\/^GBASE^\\1\/g' |sed 's\/# SET timestamp=\\(&#91;0-9]*\\);\/\/g' |sed 's\/# # administrator command: \\(&#91;0-9]*\\);\/\/g' |sed 's\/# Sql_text:\\(.*\\)\/^GBASE^\\1\/g' |sed 's\/# Sql_type:\\(.*\\);\/^GBASE^\\1\/g' |sed 's\/# Sql_command: \\(.*\\)\/^GBASE^\\1\/g' |sed 's\/# Status: \\(.*\\)\/^GBASE^\\1\/g' |sed 's\/# Connect Type: \\(.*\\);\/^GBASE^\\1^GBASE_GBASE^\/g'  &gt; tmp_auditlog_load.log\n\ngccli -vvv  -u${username} -p${password} -e\"load data infile 'sftp:\/\/gbase:gbase1234@10.0.2.201\/home\/gbase\/zxq\/audit_log\/tmp_auditlog_load.log' into table ${dbname}.${tablename} fields terminated by '^GBASE^' TABLE_FIELDS 'Threadid,Taskid,Time,End_time,User_Host,UID,Query_time,Rows,Tables_list,Sql_text,Sql_command,sql_type,Status,conn_type' lines terminated by '^GBASE_GBASE^' DATETIME FORMAT '%y%m%d %H:%i:%s'\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%BF%90%E8%A1%8C%E6%A0%B7%E4%BE%8B\"><\/span>\u8fd0\u884c\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;gbase@rh6-1 audit_log]$ sh auditlog_load.sh gclusterd-audit.log gbase gbase20110531 al al\n--------------\nload data infile 'sftp:\/\/gbase:gbase1234@10.0.2.201\/home\/gbase\/zxq\/audit_log\/tmp_auditlog_load.log' into table al.al fields terminated by '^GBASE^' TABLE_FIELDS 'Threadid,Taskid,Time,End_time,User_Host,UID,Query_time,Rows,Tables_list,Sql_text,Sql_command,sql_type,Status,conn_type' lines terminated by '^GBASE_GBASE^' DATETIME FORMAT '%y%m%d %H:%i:%s'\n--------------\n\nQuery OK, 7 rows affected (Elapsed: 00:00:01.73)\nTask 73 finished, Loaded 7 records, Skipped 28 records\n\nBye\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9%E5%92%8C%E9%99%90%E5%88%B6\"><\/span>\u6ce8\u610f\u4e8b\u9879\u548c\u9650\u5236<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u6240\u6709\u4ece\u5ba2\u6237\u7aef\u53d1\u6765\u7684SQL,\u90fd\u80fd\u88ab\u52a0\u8f7d\uff0c\u800c\u6570\u636e\u5e93\u5185\u90e8\u4e92\u76f8\u53d1\u7684SQL, \u4ece\u539f\u59cb\u6570\u636e\u770b\uff0c\u6ca1\u6709TIME\u5b57\u6bb5\uff0c\u53ea\u6709END_TIME<br>\u6bd4\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Threadid=52;\n# Taskid=0;\n# End_time: 211025 13:00:01\n# User@Host: root&#91;root] @  &#91;10.0.2.201]\n# UID: 1\n# Query_time: 0.000228 Rows: 0\n# SET timestamp=1635138001;\n# administrator command: Quit;\n# Sql_type: OTHERS;\n# Sql_command: Quit;\n# Status: SUCCESS;\n# Connect Type: CAPI;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u60f3\u8fd9\u7c7b\u5185\u90e8SQL\u4e5f\u52a0\u8f7d\uff0c\u53ea\u80fd<\/p>\n\n\n\n<p>1\u3001\u727a\u7272\u6389\u5176\u5b83SQL\u7684TIME\u5b57\u6bb5\uff0csed\u65f6\u66ff\u6362\u6210\u7a7a<br>2\u3001\u52062\u6b21\u52a0\u8f7d\uff0c\u7b2c\u4e00\u6b21\u5e26TIME\u5b57\u6bb5\uff0c\u5176\u5b83\u7684\u4e3a\u9519\u8bef\u6570\u636e\uff0c\u7b2c\u4e8c\u6b21\u4e0d\u5e26TIME\u5b57\u6bb5\u3002<br>3\u3001\u5176\u5b83\u7684\u6ca1\u52a0\u8f7d\u6210\u529f\u7684\uff0c\u5c31\u7b97\u4e86\u5427<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; load data infile 'sftp:\/\/gbase:gbase1234@10.0.2.201\/home\/gbase\/zxq\/audit_log\/al.log' into table al fields terminated by '$GBASE$' TABLE_FIELDS 'Threadid,Taskid,Time,End_time,User_Host,UID,Query_time,Rows,Tables_list,Sql_text,Sql_command,sql_type,Status,conn_type' lines terminated by '$GBASE_GBASE$' DATETIME FORMAT '%y%m%d %H:%i:%s';\nQuery OK, 7 rows affected (Elapsed: 00:00:01.62)\nTask 74 finished, Loaded 7 records, Skipped 28 records\n\ngbase&gt; load data infile 'sftp:\/\/gbase:gbase1234@10.0.2.201\/home\/gbase\/zxq\/audit_log\/al.log' into table al fields terminated by '$GBASE$' TABLE_FIELDS 'Threadid,Taskid,End_time,User_Host,UID,Query_time,Rows,Tables_list,Sql_text,Sql_command,sql_type,Status,conn_type' lines terminated by '$GBASE_GBASE$' DATETIME FORMAT '%y%m%d %H:%i:%s';\nQuery OK, 18 rows affected (Elapsed: 00:00:01.39)\nTask 75 finished, Loaded 18 records, Skipped 17 records\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Python%E5%A4%84%E7%90%86%E6%96%B9%E6%A1%88%E5%BB%BA%E8%AE%AE\"><\/span>Python\u5904\u7406\u65b9\u6848(\u5efa\u8bae)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%84%9A%E6%9C%AC\"><\/span>\u811a\u672c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5176\u4e2d\u65e5\u5fd7\u6587\u4ef6\u540d\u5199\u6b7b\u4e86\uff0c\u8bf7\u81ea\u884c\u4fee\u6539\u3002 \u539f\u7406\u5c31\u662f\u6309\u7167\\n# Threadid=\u5206\u5272\u6210\u591a\u6761\u8bb0\u5f55\uff0c\u7136\u540e\u5728\u4e00\u4e2a\u8bb0\u5f55\u5185\uff0c\u518d\u5206\u5272\uff0c\u5e76\u9010\u4e2a\u5b57\u6bb5\u7684\u626b\u63cf\u5339\u914d\u3002 \u7ee7\u7eed\u7528\u81ea\u5b9a\u4e49\u5206\u9694\u7b26\u505a\u5b57\u6bb5\u548c\u884c\u5206\u9694\u7b26\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff0c\u76f8\u6bd4shell\u811a\u672c\u7684\u7248\u672c\uff0c<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5bf9\u65e5\u671f\u5b57\u6bb5\u5df2\u7ecf\u505a\u4e86\u683c\u5f0f\u5316\u5904\u7406<\/li><li>\u5f00\u59cb\u65f6\u95f4\u4f1a\u9009\u62e9time\u5b57\u6bb5\u548ctimestamp\u5b57\u6bb5\u4e2d\u7684\u4e00\u4e2a<\/li><li>\u5206\u5272\u7b26\u4e2d\uff0c\u786e\u5b9e\u53d1\u73b0\u4e86\u90e8\u5206\u6570\u636e\u7531\u4e8e\\x00, \u5185\u90e8\u505a\u4e86replace\u5904\u7406<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@rh6-1 gbase]# cat auditlog.py\r\nfrom datetime import datetime\r\n\r\nfo = open('gclusterd-audit.log')\r\nstr = fo.read()\r\nx=str.split('\\n# Threadid=')\r\nnum=0\r\nfor part in x:\r\n  num = num + 1\r\n  ps=part.replace('\\n\\x00#','\\n#').split('\\n# ')\r\n  threadid=ps&#91;0].strip(';')\r\n  taskid=0\r\n  starttime=''\r\n  timestamp=''\r\n  endtime=''\r\n  user=''\r\n  host=''\r\n  uid=0\r\n  querytime=0\r\n  rows=0\r\n  sqltext=''\r\n  status=''\r\n  sqltype=''\r\n  sqlcommand=''\r\n  contype=''\r\n  for index in range(1,len(ps)):\r\n    if ps&#91;index].startswith('Taskid='):\r\n      taskid=ps&#91;index].split('=')&#91;1].strip(';')\r\n    elif ps&#91;index].startswith('Time: '):\r\n      starttime=datetime.strptime(ps&#91;index].split(':',1)&#91;1].strip(),'%y%m%d %H:%M:%S')\r\n    elif ps&#91;index].startswith('SET timestamp='):\r\n      timestamp=datetime.fromtimestamp(int(ps&#91;index].split('=')&#91;1].strip(';')))\r\n    elif ps&#91;index].startswith('End_time:'):\r\n      endtime=datetime.strptime(ps&#91;index].split(':',1)&#91;1].strip(),'%y%m%d %H:%M:%S')\r\n    elif ps&#91;index].startswith('User@Host'):\r\n      userhost=ps&#91;index].split(': ',1)&#91;1].strip().split('@')\r\n      user=userhost&#91;0].strip()\r\n      host=userhost&#91;1].strip()\r\n    elif ps&#91;index].startswith('UID:'):\r\n      uid=ps&#91;index].split(': ',1)&#91;1].strip()\r\n    elif ps&#91;index].startswith('Query_time'):\r\n      qt=ps&#91;index].split(': ',1)&#91;1].split('Rows:')\r\n      querytime=qt&#91;0].strip()\r\n      rows=qt&#91;1].strip()\r\n    elif ps&#91;index].startswith('Sql_text:'):\r\n      sqltext=ps&#91;index].split(': ',1)&#91;1].strip(';')\r\n    elif ps&#91;index].startswith('Status:'):\r\n      status=ps&#91;index].split(': ',1)&#91;1].strip(';')\r\n    elif ps&#91;index].startswith('Sql_type:'):\r\n      sqltype=ps&#91;index].split(': ',1)&#91;1].strip(';')\r\n    elif ps&#91;index].startswith('Sql_command:'):\r\n      sqlcommand=ps&#91;index].split(': ',1)&#91;1].strip(';')\r\n    elif ps&#91;index].startswith('Connect Type:'):\r\n      contype=ps&#91;index].split(': ',1)&#91;1].strip(';\\n')\r\n#  print(\"\\n------------------------%s------\\nthreadid=%s,taskid=%s,starttime=%s,timestamp=%s,userhost=%s,uid=%s,querytime=%s,rows=%s,sqltext=%s,status=%s,sqltype=%s,sqlcommand=%s,contype=%s#\" %(num,threadid,taskid,starttime,timestamp,userhost,uid,querytime,rows,sqltext,status,sqltype,sqlcommand,contype))\r\n  if starttime=='':\r\n    starttime=timestamp\r\n  print('%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE^%s^GBASE_GBASE^' %(threadid,taskid,starttime,endtime,user,host,uid,querytime,rows,sqltext,status,sqltype,sqlcommand,contype))\r\n\r\nfo.close()\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%BB%BA%E8%A1%A8%E8%AF%AD%E5%8F%A5\"><\/span>\u5efa\u8868\u8bed\u53e5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>create table auditlog_load(\r\nthread_id bigint,\r\ntaskid bigint,\r\nstart_time datetime,\r\nend_time datetime,\r\nuser varchar(200),\r\nhost varchar(200),\r\nuid bigint,\r\nquerytime decimal(16,6),\r\nrows bigint,\r\nsql_text text,\r\nstatus varchar(20) ,\r\nsql_type varchar(20),\r\nsql_command text,\r\nconn_type varchar(100)\r\n);\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8A%A0%E8%BD%BD%E6%96%B9%E5%BC%8F\"><\/span>\u52a0\u8f7d\u65b9\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>load data infile 'sftp:\/\/gbase:gbase1234@10.0.2.201\/home\/gbase\/audit_toload.txt' into table auditlog_load fields terminated by '^GBASE^' lines terminated by '^GBASE_GBASE^\\n' DATETIME FORMAT '%Y-%m-%d %H:%i:%s';\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u4e00\u79cd\uff0c\u4ece\u6587\u672c\u683c\u5f0f\u7684\u5ba1\u8ba1\u65e5\u5fd7\uff0c\u901a\u8fc7\u66ff\u6362\u81ea\u5b9a\u4e49\u5b57\u6bb5\u548c\u884c\u5206\u9694\u7b26\uff0c\u52a0\u8f7d\u5230GBase 8a\u6570\u636e\u5e93\u7684\u65b9\u6cd5\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[10],"class_list":["post-8272","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-10"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=8272"}],"version-history":[{"count":10,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8272\/revisions"}],"predecessor-version":[{"id":8621,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8272\/revisions\/8621"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=8272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=8272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=8272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}