简体   繁体   English

AWS RDS 上 MySQL 通用查询日志的大小

[英]Size of MySQL general query log on AWS RDS

I'm trying to find the size of my general query log.我试图找到我的一般查询日志的大小。 I can't find out via the mysql interface, since it's stored via CSV engine (and it just shows 0 when queried):我无法通过 mysql 界面找到,因为它是通过 CSV 引擎存储的(并且在查询时只显示 0):

show table status from mysql;

# Name, Engine, Version, Row_format, Rows, Avg_row_length, Data_length, Max_data_length, Index_length, Data_free, Auto_increment, Create_time, Update_time, Check_time, Collation, Checksum, Create_options, Comment

'general_log', 'CSV', '10', 'Dynamic', '1', '0', '0', '0', '0', '0', NULL, NULL, NULL, NULL, 'utf8_general_ci', NULL, '', 'General log'

I know there are at least 100k rows in there (mostly queries) by manually inspecting it via:通过手动检查,我知道那里至少有 100k 行(主要是查询):

select * from mysql.general_log;

The thing is, I can't seem to find a way to access the log from AWS console side.问题是,我似乎找不到从 AWS 控制台端访问日志的方法。 From the management console, there is only the very general log (with the following info in it):从管理控制台,只有非常一般的日志(其中包含以下信息):

/rdsdbbin/mysql/bin/mysqld, Version: 5.6.23-log (MySQL Community Server (GPL)). /rdsdbbin/mysql/bin/mysqld,版本:5.6.23-log(MySQL 社区服务器(GPL))。 started with: Tcp port: 3306 Unix socket: /tmp/mysql.sock开始于:Tcp 端口:3306 Unix 套接字:/tmp/mysql.sock

... more of the same ...更多相同

I can't get to the actual csv since I don't have control over the actual server.我无法访问实际的 csv,因为我无法控制实际的服务器。

Does anyone have a clever way of getting the table size?有没有人有一种聪明的方法来获得桌子的大小? At worst I can count the length of each field and estimate via row counts?最坏的情况是我可以计算每个字段的长度并通过行数进行估计?

What I ended up doing is querying the size from the MySQL console, and estimated the size based on column types.我最终做的是从 MySQL 控制台查询大小,并根据列类型估计大小。

DESCRIBE mysql.general_log;
SELECT COUNT(*) FROM mysql.general_log;

You'll see 6 cols, each with relatively fixed size, except for the two MEDIUM TEXT cols, which you'll have to estimate.您将看到 6 个列,每个列的大小相对固定,除了两个MEDIUM TEXT ,您必须对其进行估计。 But you'll be able to get a decent ball mark.但是你将能够获得一个不错的球标。

(Copied from https://bugs.mysql.com/bug.php?id=53929 ) (复制自https://bugs.mysql.com/bug.php?id=53929

You can add the following procedure, which will determine the exact size of a CSV table from a mysql console:您可以添加以下过程,这将从 mysql 控制台确定 CSV 表的确切大小:

DELIMITER //
DROP PROCEDURE IF EXISTS checkcsv//
CREATE PROCEDURE checkcsv(IN databasename CHAR(200),IN tablename CHAR(200))
BEGIN
  SET SESSION group_concat_max_len=10*1024*1024; /* 10Mb buffer for CONCAT_WS */
  SELECT GROUP_CONCAT(COLUMN_NAME) INTO @columnames FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_SCHEMA = databasename AND TABLE_NAME = tablename);
  SET @get_colsizes_stmt = CONCAT("SELECT SUM(CHAR_LENGTH(REPLACE(REPLACE(REPLACE(CONCAT_WS(',',",@columnames,"),UNHEX('0A'),'nn'),UNHEX('22'),'nn'),UNHEX('5C'),'nn'))) INTO @total_length FROM ",databasename,".",tablename,";");
  PREPARE get_colsizes FROM @get_colsizes_stmt;
  EXECUTE get_colsizes;
  DEALLOCATE PREPARE get_colsizes;
  SET @get_count_stmt = CONCAT('SELECT COUNT(*) INTO @rowcount FROM ',databasename,'.',tablename,';');
  PREPARE get_count FROM @get_count_stmt;
  EXECUTE get_count;
  DEALLOCATE PREPARE get_count;
  SELECT 2*COUNT(COLUMN_NAME) INTO @non_numeric_cols_count FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_SCHEMA = databasename AND TABLE_NAME = tablename AND NUMERIC_SCALE IS NULL); /* Counting quotes */
  SET @total_size=@total_length+(@rowcount*@non_numeric_cols_count) /* Adding counted quotes */ +@rowcount /* one LineFeed per row */;
  SET @avg_row_length=@total_size/@rowcount;
  SET @output_stmt = CONCAT ("SELECT CONCAT('",databasename,"','.','",tablename,"') AS 'Table', ",@rowcount," AS 'Number Of Rows', ROUND(@avg_row_length) AS 'Average Row Length', ",ROUND(@total_size)," AS 'Total size' FROM ",databasename,".",tablename," LIMIT 1;");
  PREPARE outputr FROM @output_stmt;
  EXECUTE outputr;
  DEALLOCATE PREPARE outputr;
END;
//
DELIMITER ;
----- 

----- Usage Example: ----- 
mysql> CALL checkcsv("mysql","general_log");
+-------------------+----------------+--------------------+------------+
| Table             | Number Of Rows | Average Row Length | Total size |
+-------------------+----------------+--------------------+------------+
| mysql.general_log |             53 |                183 |       9673 |
+-------------------+----------------+--------------------+------------+
1 row in set (0.01 sec)

Query OK, 0 rows affected (0.06 sec)
----- 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM