AWS RDS如何用CLI命令获取和下载实例上的慢查询日志

首先需要找到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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2145216/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值