mysql_get_table_stats
Retrieve table statistics including row count and size from MySQL databases to monitor performance and optimize storage.
Instructions
Get statistics about a table (row count, size, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name to get statistics for | |
| database | No | Database name (uses current database if not specified) |
Implementation Reference
- src/index.ts:448-491 (handler)The handler function that implements the mysql_get_table_stats tool by querying INFORMATION_SCHEMA.TABLES for table statistics including row count, engine, data length, index length, and other metrics.private async handleGetTableStats(args: any) { if (!this.pool) { throw new Error("Not connected to MySQL. Use mysql_connect first."); } const { table, database } = args; if (!table) { throw new Error("Table name is required"); } try { // Get table information from information_schema const dbCondition = database ? `AND TABLE_SCHEMA = '${database}'` : ""; const query = ` SELECT TABLE_NAME, ENGINE, TABLE_ROWS, DATA_LENGTH, INDEX_LENGTH, DATA_FREE, AUTO_INCREMENT, CREATE_TIME, UPDATE_TIME, CHECK_TIME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '${table}' ${dbCondition} `; const [results] = await this.pool.execute(query); return { content: [ { type: "text", text: `Statistics for table '${table}':\n${JSON.stringify(results, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to get table statistics: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:214-231 (registration)Tool registration in the listTools handler, defining the name, description, and input schema for mysql_get_table_stats.{ name: "mysql_get_table_stats", description: "Get statistics about a table (row count, size, etc.)", inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to get statistics for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], }, },
- src/index.ts:217-230 (schema)Input schema definition for the mysql_get_table_stats tool, specifying required 'table' parameter and optional 'database'.inputSchema: { type: "object", properties: { table: { type: "string", description: "Table name to get statistics for", }, database: { type: "string", description: "Database name (uses current database if not specified)", }, }, required: ["table"], },