mysql> use information_schema;
Database changed
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES;
+----------+
| data |
+----------+
| 868.34MB |
+----------+
1 row in set (0.04 sec)
查看指定库的大小
mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='fncftc_sql';
+----------+
| data |
+----------+
| 858.37MB |
+----------+
1 row in set (0.01 sec)
查看指定库的指定表的大小
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='fncftc_sql' and table_name='fanwe_money_detail';
+----------+
| data |
+----------+
| 170.92MB |
+----------+
1 row in set (0.00 sec)
查看指定库的索引大小
mysql> select concat(round(sum(index_length/1024/1024),2),'MB') as 'Total Index Size' from TABLES where table_schema='fncftc_sql';
+------------------+
| Total Index Size |
+------------------+
| 787.33MB |
+------------------+
1 row in set (0.00 sec)
查看指定库的指定表的索引大小
mysql> select concat(round(sum(index_length/1024/1024),2),'MB') as 'Total Index Size' from TABLES where table_schema='fncftc_sql' and table_name='fanwe_money_detail';
+------------------+
| Total Index Size |
+------------------+
| 256.72MB |
+------------------+
1 row in set (0.00 sec)
查看一个库中的情况
mysql> SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', CONCAT(ROUND(table_rows/1000000,4),'M') AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'fncftc_sql';
+------------------------------------------------------+----------------+-----------+------------+---------+
| Table Name | Number of Rows | Data Size | Index Size | Total |
+------------------------------------------------------+----------------+-----------+------------+---------+
| fncftc_sql.fanwe_about_rules | 0.0000M | 0.0000G | 0.0000G | 0.0000G |
| fncftc_sql.fanwe_account_record | 0.0000M | 0.0000G | 0.0000G | 0.0000G |
| fncftc_sql.fanwe_activit | 0.0000M | 0.0000G | 0.0000G | 0.0000G |
| fncftc_sql.fanwe_activit_cash | 0.0000M | 0.0000G | 0.0000G | 0.0000G |
| fncftc_sql.fanwe_activit_order | 0.0021M | 0.0003G | 0.0001G | 0.0004G |
连接数
实时连接数
cd /usr/local/mysql/bin
./mysqladmin -uquma -p processlist
或
mysql> show full processlist
只查看当前连接数
./mysqladmin -uquma -p status
Enter password:
Uptime: 656028 Threads: 37 Questions: 117890362 Slow queries: 331 Opens: 10325 Flush tables: 15 Open tables: 659 Queries per second avg: 179.703
通过
MySQL
的information_schema
数据库,可查询数据库中每个表占用的空间、表记录的行数;该库中有一个TABLES
表,这个表主要字段分别是:TABLE_SCHEMA :
数据库名TABLE_NAME:
表名ENGINE:
所使用的存储引擎TABLES_ROWS:
记录数DATA_LENGTH:
数据大小INDEX_LENGTH:
索引大小其他字段请参考
MySQL
的手册,查看一个表占用空间的大小,那就相当于是 数据大小 + 索引大小 。查看所有库的大小
查看指定库的大小
查看指定库的指定表的大小
查看指定库的索引大小
查看指定库的指定表的索引大小
查看一个库中的情况
连接数
实时连接数
或
只查看当前连接数
上面的
Threads
就是连接数, 其他参数含义如下:Uptime
: `MySQL 服务运行的时间(秒)Threads
:客户线程数量Questions
:MySQl
服务启动后的查询数量Slow queries
:慢查询数量,通过long_query_time
设置慢查询Opens
:服务器打开过的表的数量Flush tables
:flush-*
,refresh
,reload
命令执行的数量Open tables
:服务器当前被打开的表数量