AWS RDS如何用CLI命令獲取和下載例項上的慢查詢日誌

chenfeng發表於2017-09-20
首先需要找到AWS Access Key ID and Secret Access Key,具體方法可以參考下文:
http://blog.iyunker.com/%E6%95%99%E4%BD%A0%E5%A6%82%E4%BD%95%E6%89%BE%E5%88%B0aws-access-key-id-and-secret-access-key/

找到後寫入~/.aws目錄的credentials檔案裡,內容舉例如下:

[root@ip-10-0-2-20 .aws]# cat credentials
[default]
aws_access_key_id = AKIAPQBIEU44HMCCACKE
aws_secret_access_key = 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

獲取MySQL慢查詢日誌檔案的列表用如下命令:

[root@ip-10-0-2-20 logs]# aws --output text rds describe-db-log-files --db-instance-identifier msj3
DESCRIBEDBLOGFILES      1505877300000   error/mysql-error.log   0
DESCRIBEDBLOGFILES      1487040936000   mysqlUpgrade    3297
DESCRIBEDBLOGFILES      1505877300000   slowquery/mysql-slowquery.log   549
DESCRIBEDBLOGFILES      1505865300000   slowquery/mysql-slowquery.log.0 2196
DESCRIBEDBLOGFILES      1505869200000   slowquery/mysql-slowquery.log.1 2379
DESCRIBEDBLOGFILES      1505815200000   slowquery/mysql-slowquery.log.10        2196
DESCRIBEDBLOGFILES      1505818500000   slowquery/mysql-slowquery.log.11        2013
DESCRIBEDBLOGFILES      1505822400000   slowquery/mysql-slowquery.log.12        2379
DESCRIBEDBLOGFILES      1505825700000   slowquery/mysql-slowquery.log.13        2013
DESCRIBEDBLOGFILES      1505829300000   slowquery/mysql-slowquery.log.14        2196
DESCRIBEDBLOGFILES      1505832900000   slowquery/mysql-slowquery.log.15        2196
DESCRIBEDBLOGFILES      1505836800000   slowquery/mysql-slowquery.log.16        2379
DESCRIBEDBLOGFILES      1505840100000   slowquery/mysql-slowquery.log.17        2013
DESCRIBEDBLOGFILES      1505844000000   slowquery/mysql-slowquery.log.18        2901
DESCRIBEDBLOGFILES      1505847300000   slowquery/mysql-slowquery.log.19        2013
DESCRIBEDBLOGFILES      1505872500000   slowquery/mysql-slowquery.log.2 2013
DESCRIBEDBLOGFILES      1505851200000   slowquery/mysql-slowquery.log.20        2562
DESCRIBEDBLOGFILES      1505854500000   slowquery/mysql-slowquery.log.21        2013
DESCRIBEDBLOGFILES      1505858400000   slowquery/mysql-slowquery.log.22        2379
DESCRIBEDBLOGFILES      1505861700000   slowquery/mysql-slowquery.log.23        2013
DESCRIBEDBLOGFILES      1505876400000   slowquery/mysql-slowquery.log.3 2379
DESCRIBEDBLOGFILES      1505793600000   slowquery/mysql-slowquery.log.4 2196
DESCRIBEDBLOGFILES      1505797200000   slowquery/mysql-slowquery.log.5 2196
DESCRIBEDBLOGFILES      1505800800000   slowquery/mysql-slowquery.log.6 2196
DESCRIBEDBLOGFILES      1505804100000   slowquery/mysql-slowquery.log.7 2013
DESCRIBEDBLOGFILES      1505808000000   slowquery/mysql-slowquery.log.8 2379
DESCRIBEDBLOGFILES      1505811600000   slowquery/mysql-slowquery.log.9 3139

下載慢查詢日誌:
例如下載slowquery/mysql-slowquery.log.6
[root@ip-10-0-2-20 logs]# aws rds download-db-log-file-portion --db-instance-identifier msj3 --log-file-name slowquery/mysql-slowquery.log.6
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument
/rdsdbbin/mysql/bin/mysqld, Version: 5.6.29-log (MySQL Community Server (GPL)). started with:
Tcp port: 3306  Unix socket: /tmp/mysql.sock
Time                 Id Command    Argument

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2145216/,如需轉載,請註明出處,否則將追究法律責任。

相關文章