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):
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:
select * from mysql.general_log;
The thing is, I can't seem to find a way to access the log from AWS console side. 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)). started with: Tcp port: 3306 Unix socket: /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.
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.
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. But you'll be able to get a decent ball mark.
(Copied from 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:
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)
-----
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.