mysql日常运维

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jing_flower/article/details/79193455

1. mysql查看数据库大小


use 数据库名


SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='数据库名';




2. mysql表占用的空间


SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS FROM TABLES WHERE TABLE_SCHEMA='数据库名' AND TABLE_NAME='表名'




3. 查看表的最后mysql修改时间


select TABLE_NAME,UPDATE_TIME from INFORMATION_SCHEMA.tables where TABLE_SCHEMA='数据库名';


4.查看当前的连接数


 show status like 'Threads%';


+-------------------+--------+
| Variable_name     | Value  |
+-------------------+--------+
| Threads_cached    | 2      |
| Threads_connected | 1183   |   //当前连接数
| Threads_created   | 337798 |
| Threads_running   | 13     |   //当前的并发数
+-------------------+--------+


5.查看最大连接数


show variables like '%max_connections%';


+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 8200  |
+-----------------+-------+
1 row in set (0.01 sec)


6.查看QPS
QPS (Query per second) (每秒查询量)


 SHOW GLOBAL STATUS LIKE 'Questions';
+---------------+-------------+
| Variable_name | Value       |
+---------------+-------------+
| Questions     | 42260778868 |
+---------------+-------------+
1 row in set (0.00 sec)


 SHOW GLOBAL STATUS LIKE 'Uptime';
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Uptime        | 26924936 |
+---------------+----------+
1 row in set (0.00 sec)


select 42260778868/26924936 AS QPS  from dual;
+-----------+
| QPS       |
+-----------+
| 1569.5777 |
+-----------+
1 row in set (0.00 sec)


7.查看tps
TPS(Transaction per second) (每秒事务量,如果是InnoDB会显示,没有InnoDB就不会显示)


 SHOW GLOBAL STATUS LIKE 'Com_commit';
+---------------+---------+
| Variable_name | Value   |
+---------------+---------+
| Com_commit    | 1676595 |
+---------------+---------+
1 row in set (0.00 sec)


SHOW GLOBAL STATUS LIKE 'Com_rollback';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_rollback  | 1     |
+---------------+-------+
1 row in set (0.01 sec)




  SHOW GLOBAL STATUS LIKE 'Uptime';
+---------------+----------+
| Variable_name | Value    |
+---------------+----------+
| Uptime        | 26925163 |
+---------------+----------+
1 row in set (0.00 sec)




select (1676595+1)/26925163 as TPS from dual;
+--------+
| TPS    |
+--------+
| 0.0623 |
+--------+

1 row in set (0.00 sec)

8. 登陆

mysql -h $IP -P $PORT -u $USER -p'$pw' -D 数据库名

 

 

展开阅读全文

没有更多推荐了,返回首页