当前位置: 首页 > MySQL数据库

Mysql怎么查询数据库连接状态及连接信息

时间:2026-01-25 16:20:12
查看显示所有数据库
mysql>showdatabases;+--------------------+|Database|+--------------------+|information_schema||INVOICE||mysql||performance_schema||test|+--------------------+5rowsinset(0.00sec)mysql>
查看当前使用的数据库
mysql>selectdatabase();+------------+|database()|+------------+|INVOICE|+------------+1rowinset(0.00sec)mysql>
查看数据库使用端口
mysql>showvariableslike'port';+---------------+-------+|Variable_name|Value|+---------------+-------+|port|3306|+---------------+-------+1rowinset(0.00sec)
查看当前数据库大小

例如,我要查看INVOICE数据库的大小,那么可以通过下面SQL查看

mysql>useinformation_schemaReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedmysql>selectconcat(round(sum(data_length)/(1024*1024),2)+round(sum(index_length)/(1024*1024),2),'MB')as'DBSize'->fromtables->wheretable_schema='INVOICE';+-----------+|DBSize|+-----------+|7929.58MB|+-----------+1rowinset,1warning(0.00sec)
查看数据所占的空间大小
mysql>useinformation_schema;ReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedmysql>selectconcat(round(sum(data_length)/(1024*1024),2),'MB')as'DBSize'->fromtables->wheretable_schema='INVOICE';+-----------+|DBSize|+-----------+|6430.26MB|+-----------+1rowinset,1warning(0.00sec)mysql>
查看索引所占的空间大小
mysql>selectconcat(round(sum(index_length)/(1024*1024),2),'MB')as'DBSize'->fromtables->wheretable_schema='INVOICE';+-----------+|DBSize|+-----------+|1499.32MB|+-----------+1rowinset,1warning(0.13sec)mysql>
查看数据库编码
mysql>showvariableslike'character%';+--------------------------+----------------------------+|Variable_name|Value|+--------------------------+----------------------------+|character_set_client|utf8||character_set_connection|utf8||character_set_database|utf8||character_set_filesystem|binary||character_set_results|utf8||character_set_server|latin1||character_set_system|utf8||character_sets_dir|/usr/share/mysql/charsets/|+--------------------------+----------------------------+8rowsinset(0.00sec)
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素