Mysql 性能统计

来源:互联网 发布:网络兼职赚钱有哪些 编辑:程序博客网 时间:2024/04/30 10:08

转载地址:http://blog.csdn.net/cloud_ll/article/details/18730361


Mysql自带了性能统计数据,可以通过show status 或者show gloabl status查看,show status查看的是当前session的统计结果,gloabl查看的是所有session的统计结果。

一般来说我们会使用show gloabl status对Mysql做一些系统性能分析,比如间隔一段时间统计两次所有statementQueries Questions ),CRUD次数(Com_select Com_delete Com_insert Com_update)和Connection的数目( max_used_connections Connections)来计算系统平均访问情况。


下面给个例子:

[plain] view plain copy 在CODE上查看代码片派生到我的代码片
  1. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql.exe -uroot -proot -e "show global status where Variable_name in ('com_select', 'com_insert',  'com_delete', 'com_update');"  
  2. Warning: Using a password on the command line interface can be insecure.  
  3. +---------------+-------+  
  4. | Variable_name | Value |  
  5. +---------------+-------+  
  6. | Com_delete    | 0     |  
  7. | Com_insert    | 0     |  
  8. | Com_select    | 1     |  
  9. | Com_update    | 0     |  
  10. +---------------+-------+  

所有可以查询的字段列出如下:

mysql> show global status;

[sql] view plain copy 在CODE上查看代码片派生到我的代码片
  1. +-----------------------------------------------+-------------+  
  2. | Variable_name                                 | Value       |  
  3. +-----------------------------------------------+-------------+  
  4. | Aborted_clients                               | 1           |  
  5. | Aborted_connects                              | 0           |  
  6. | Binlog_cache_disk_use                         | 0           |  
  7. | Binlog_cache_use                              | 0           |  
  8. | Binlog_stmt_cache_disk_use                    | 0           |  
  9. | Binlog_stmt_cache_use                         | 0           |  
  10. | <strong>Bytes_received                                | 634         |  
  11. | Bytes_sent                                    | 28498 </strong>      |  
  12. | Com_admin_commands                            | 0           |  
  13. | Com_assign_to_keycache                        | 0           |  
  14. | Com_alter_db                                  | 0           |  
  15. | Com_alter_db_upgrade                          | 0           |  
  16. | Com_alter_event                               | 0           |  
  17. | Com_alter_function                            | 0           |  
  18. | Com_alter_procedure                           | 0           |  
  19. | Com_alter_server                              | 0           |  
  20. | Com_alter_table                               | 0           |  
  21. | Com_alter_tablespace                          | 0           |  
  22. | Com_alter_user                                | 0           |  
  23. | Com_analyze                                   | 0           |  
  24. | Com_begin                                     | 0           |  
  25. | Com_binlog                                    | 0           |  
  26. | Com_call_procedure                            | 0           |  
  27. | Com_change_db                                 | 1           |  
  28. | Com_change_master                             | 0           |  
  29. | Com_check                                     | 0           |  
  30. | Com_checksum                                  | 0           |  
  31. | Com_commit                                    | 0           |  
  32. | Com_create_db                                 | 0           |  
  33. | Com_create_event                              | 0           |  
  34. | Com_create_function                           | 0           |  
  35. | Com_create_index                              | 0           |  
  36. | Com_create_procedure                          | 0           |  
  37. | Com_create_server                             | 0           |  
  38. | Com_create_table                              | 0           |  
  39. | Com_create_trigger                            | 0           |  
  40. | Com_create_udf                                | 0           |  
  41. | Com_create_user                               | 0           |  
  42. | Com_create_view                               | 0           |  
  43. | Com_dealloc_sql                               | 0           |  
  44. | Com_delete                                    | 0           |  
  45. | Com_delete_multi                              | 0           |  
  46. | Com_do                                        | 0           |  
  47. | Com_drop_db                                   | 0           |  
  48. | Com_drop_event                                | 0           |  
  49. | Com_drop_function                             | 0           |  
  50. | Com_drop_index                                | 0           |  
  51. | Com_drop_procedure                            | 0           |  
  52. | Com_drop_server                               | 0           |  
  53. | Com_drop_table                                | 0           |  
  54. | Com_drop_trigger                              | 0           |  
  55. | Com_drop_user                                 | 0           |  
  56. | Com_drop_view                                 | 0           |  
  57. | Com_empty_query                               | 0           |  
  58. | Com_execute_sql                               | 0           |  
  59. | Com_flush                                     | 0           |  
  60. | Com_get_diagnostics                           | 0           |  
  61. | Com_grant                                     | 0           |  
  62. | Com_ha_close                                  | 0           |  
  63. | Com_ha_open                                   | 0           |  
  64. | Com_ha_read                                   | 0           |  
  65. | Com_help                                      | 0           |  
  66. | Com_insert                                    | 0           |  
  67. | Com_insert_select                             | 0           |  
  68. | Com_install_plugin                            | 0           |  
  69. | Com_kill                                      | 0           |  
  70. | Com_load                                      | 0           |  
  71. | Com_lock_tables                               | 0           |  
  72. | Com_optimize                                  | 0           |  
  73. | Com_preload_keys                              | 0           |  
  74. | Com_prepare_sql                               | 0           |  
  75. | Com_purge                                     | 0           |  
  76. | Com_purge_before_date                         | 0           |  
  77. | Com_release_savepoint                         | 0           |  
  78. | Com_rename_table                              | 0           |  
  79. | Com_rename_user                               | 0           |  
  80. | Com_repair                                    | 0           |  
  81. | Com_replace                                   | 0           |  
  82. | Com_replace_select                            | 0           |  
  83. | Com_reset                                     | 0           |  
  84. | Com_resignal                                  | 0           |  
  85. | Com_revoke                                    | 0           |  
  86. | Com_revoke_all                                | 0           |  
  87. | Com_rollback                                  | 0           |  
  88. | Com_rollback_to_savepoint                     | 0           |  
  89. | Com_savepoint                                 | 0           |  
  90. | Com_select                                    | 2           |  
  91. | Com_set_option                                | 0           |  
  92. | Com_signal                                    | 0           |  
  93. | Com_show_binlog_events                        | 0           |  
  94. | Com_show_binlogs                              | 0           |  
  95. | Com_show_charsets                             | 0           |  
  96. | Com_show_collations                           | 0           |  
  97. | Com_show_create_db                            | 0           |  
  98. | Com_show_create_event                         | 0           |  
  99. | Com_show_create_func                          | 0           |  
  100. | Com_show_create_proc                          | 0           |  
  101. | Com_show_create_table                         | 0           |  
  102. | Com_show_create_trigger                       | 0           |  
  103. | Com_show_databases                            | 1           |  
  104. | Com_show_engine_logs                          | 0           |  
  105. | Com_show_engine_mutex                         | 0           |  
  106. | Com_show_engine_status                        | 0           |  
  107. | Com_show_events                               | 0           |  
  108. | Com_show_errors                               | 0           |  
  109. | Com_show_fields                               | 0           |  
  110. | Com_show_function_code                        | 0           |  
  111. | Com_show_function_status                      | 0           |  
  112. | Com_show_grants                               | 0           |  
  113. | Com_show_keys                                 | 0           |  
  114. | Com_show_master_status                        | 0           |  
  115. | Com_show_open_tables                          | 0           |  
  116. | Com_show_plugins                              | 0           |  
  117. | Com_show_privileges                           | 0           |  
  118. | Com_show_procedure_code                       | 0           |  
  119. | Com_show_procedure_status                     | 0           |  
  120. | Com_show_processlist                          | 0           |  
  121. | Com_show_profile                              | 0           |  
  122. | Com_show_profiles                             | 0           |  
  123. | Com_show_relaylog_events                      | 0           |  
  124. | Com_show_slave_hosts                          | 0           |  
  125. | Com_show_slave_status                         | 0           |  
  126. | Com_show_status                               | 4           |  
  127. | Com_show_storage_engines                      | 0           |  
  128. | Com_show_table_status                         | 0           |  
  129. | Com_show_tables                               | 0           |  
  130. | Com_show_triggers                             | 0           |  
  131. | Com_show_variables                            | 0           |  
  132. | Com_show_warnings                             | 0           |  
  133. | Com_slave_start                               | 0           |  
  134. | Com_slave_stop                                | 0           |  
  135. | Com_stmt_close                                | 0           |  
  136. | Com_stmt_execute                              | 0           |  
  137. | Com_stmt_fetch                                | 0           |  
  138. | Com_stmt_prepare                              | 0           |  
  139. | Com_stmt_reprepare                            | 0           |  
  140. | Com_stmt_reset                                | 0           |  
  141. | Com_stmt_send_long_data                       | 0           |  
  142. | Com_truncate                                  | 0           |  
  143. | Com_uninstall_plugin                          | 0           |  
  144. | Com_unlock_tables                             | 0           |  
  145. | Com_update                                    | 0           |  
  146. | Com_update_multi                              | 0           |  
  147. | Com_xa_commit                                 | 0           |  
  148. | Com_xa_end                                    | 0           |  
  149. | Com_xa_prepare                                | 0           |  
  150. | Com_xa_recover                                | 0           |  
  151. | Com_xa_rollback                               | 0           |  
  152. | Com_xa_start                                  | 0           |  
  153. | Compression                                   | OFF         |  
  154. | Connection_errors_accept                      | 0           |  
  155. | Connection_errors_internal                    | 0           |  
  156. | Connection_errors_max_connections             | 0           |  
  157. | Connection_errors_peer_address                | 0           |  
  158. | Connection_errors_select                      | 0           |  
  159. | Connection_errors_tcpwrap                     | 0           |  
  160. | Connections                                   | 3           |  
  161. | Created_tmp_disk_tables                       | 0           |  
  162. | Created_tmp_files                             | 5           |  
  163. | Created_tmp_tables                            | 5           |  
  164. | Delayed_errors                                | 0           |  
  165. | Delayed_insert_threads                        | 0           |  
  166. | Delayed_writes                                | 0           |  
  167. | Flush_commands                                | 1           |  
  168. | Handler_commit                                | 0           |  
  169. | Handler_delete                                | 0           |  
  170. | Handler_discover                              | 0           |  
  171. | Handler_external_lock                         | 140         |  
  172. | Handler_mrr_init                              | 0           |  
  173. | Handler_prepare                               | 0           |  
  174. | Handler_read_first                            | 3           |  
  175. | Handler_read_key                              | 0           |  
  176. | Handler_read_last                             | 0           |  
  177. | Handler_read_next                             | 0           |  
  178. | Handler_read_prev                             | 0           |  
  179. | Handler_read_rnd                              | 0           |  
  180. | Handler_read_rnd_next                         | 1054        |  
  181. | Handler_rollback                              | 0           |  
  182. | Handler_savepoint                             | 0           |  
  183. | Handler_savepoint_rollback                    | 0           |  
  184. | Handler_update                                | 0           |  
  185. | Handler_write                                 | 1033        |  
  186. | Innodb_buffer_pool_dump_status                | not started |  
  187. | Innodb_buffer_pool_load_status                | not started |  
  188. | Innodb_buffer_pool_pages_data                 | 407         |  
  189. | Innodb_buffer_pool_bytes_data                 | 6668288     |  
  190. | Innodb_buffer_pool_pages_dirty                | 0           |  
  191. | Innodb_buffer_pool_bytes_dirty                | 0           |  
  192. | Innodb_buffer_pool_pages_flushed              | 1           |  
  193. | Innodb_buffer_pool_pages_free                 | 1449        |  
  194. | Innodb_buffer_pool_pages_misc                 | 0           |  
  195. | Innodb_buffer_pool_pages_total                | 1856        |  
  196. | Innodb_buffer_pool_read_ahead_rnd             | 0           |  
  197. | Innodb_buffer_pool_read_ahead                 | 0           |  
  198. | Innodb_buffer_pool_read_ahead_evicted         | 0           |  
  199. | Innodb_buffer_pool_read_requests              | 3104        |  
  200. | Innodb_buffer_pool_reads                      | 408         |  
  201. | Innodb_buffer_pool_wait_free                  | 0           |  
  202. | Innodb_buffer_pool_write_requests             | 1           |  
  203. | Innodb_data_fsyncs                            | 5           |  
  204. | Innodb_data_pending_fsyncs                    | 0           |  
  205. | Innodb_data_pending_reads                     | 0           |  
  206. | Innodb_data_pending_writes                    | 0           |  
  207. | Innodb_data_read                              | 10833920    |  
  208. | Innodb_data_reads                             | 627         |  
  209. | Innodb_data_writes                            | 5           |  
  210. | Innodb_data_written                           | 34304       |  
  211. | Innodb_dblwr_pages_written                    | 1           |  
  212. | Innodb_dblwr_writes                           | 1           |  
  213. | Innodb_have_atomic_builtins                   | ON          |  
  214. | Innodb_log_waits                              | 0           |  
  215. | Innodb_log_write_requests                     | 0           |  
  216. | Innodb_log_writes                             | 1           |  
  217. | Innodb_os_log_fsyncs                          | 3           |  
  218. | Innodb_os_log_pending_fsyncs                  | 0           |  
  219. | Innodb_os_log_pending_writes                  | 0           |  
  220. | Innodb_os_log_written                         | 512         |  
  221. | Innodb_page_size                              | 16384       |  
  222. | Innodb_pages_created                          | 0           |  
  223. | Innodb_pages_read                             | 407         |  
  224. | Innodb_pages_written                          | 1           |  
  225. | Innodb_row_lock_current_waits                 | 0           |  
  226. | Innodb_row_lock_time                          | 0           |  
  227. | Innodb_row_lock_time_avg                      | 0           |  
  228. | Innodb_row_lock_time_max                      | 0           |  
  229. | Innodb_row_lock_waits                         | 0           |  
  230. | Innodb_rows_deleted                           | 0           |  
  231. | Innodb_rows_inserted                          | 0           |  
  232. | Innodb_rows_read                              | 0           |  
  233. | Innodb_rows_updated                           | 0           |  
  234. | Innodb_num_open_files                         | 6           |  
  235. | Innodb_truncated_status_writes                | 0           |  
  236. | Innodb_available_undo_logs                    | 128         |  
  237. | Key_blocks_not_flushed                        | 0           |  
  238. | Key_blocks_unused                             | 6698        |  
  239. | Key_blocks_used                               | 0           |  
  240. | Key_read_requests                             | 0           |  
  241. | Key_reads                                     | 0           |  
  242. | Key_write_requests                            | 0           |  
  243. | Key_writes                                    | 0           |  
  244. | Last_query_cost                               | 0.000000    |  
  245. | Last_query_partial_plans                      | 0           |  
  246. | Max_used_connections                          | 1           |  
  247. | Not_flushed_delayed_rows                      | 0           |  
  248. | Open_files                                    | 17          |  
  249. | Open_streams                                  | 0           |  
  250. | Open_table_definitions                        | 67          |  
  251. | Open_tables                                   | 60          |  
  252. | Opened_files                                  | 117         |  
  253. | Opened_table_definitions                      | 67          |  
  254. | Opened_tables                                 | 67          |  
  255. | Performance_schema_accounts_lost              | 0           |  
  256. | Performance_schema_cond_classes_lost          | 0           |  
  257. | Performance_schema_cond_instances_lost        | 0           |  
  258. | Performance_schema_digest_lost                | 0           |  
  259. | Performance_schema_file_classes_lost          | 0           |  
  260. | Performance_schema_file_handles_lost          | 0           |  
  261. | Performance_schema_file_instances_lost        | 0           |  
  262. | Performance_schema_hosts_lost                 | 0           |  
  263. | Performance_schema_locker_lost                | 0           |  
  264. | Performance_schema_mutex_classes_lost         | 0           |  
  265. | Performance_schema_mutex_instances_lost       | 0           |  
  266. | Performance_schema_rwlock_classes_lost        | 0           |  
  267. | Performance_schema_rwlock_instances_lost      | 0           |  
  268. | Performance_schema_session_connect_attrs_lost | 0           |  
  269. | Performance_schema_socket_classes_lost        | 0           |  
  270. | Performance_schema_socket_instances_lost      | 0           |  
  271. | Performance_schema_stage_classes_lost         | 0           |  
  272. | Performance_schema_statement_classes_lost     | 0           |  
  273. | Performance_schema_table_handles_lost         | 0           |  
  274. | Performance_schema_table_instances_lost       | 0           |  
  275. | Performance_schema_thread_classes_lost        | 0           |  
  276. | Performance_schema_thread_instances_lost      | 0           |  
  277. | Performance_schema_users_lost                 | 0           |  
  278. | Prepared_stmt_count                           | 0           |  
  279. | Qcache_free_blocks                            | 0           |  
  280. | Qcache_free_memory                            | 0           |  
  281. | Qcache_hits                                   | 0           |  
  282. | Qcache_inserts                                | 0           |  
  283. | Qcache_lowmem_prunes                          | 0           |  
  284. | Qcache_not_cached                             | 0           |  
  285. | Qcache_queries_in_cache                       | 0           |  
  286. | Qcache_total_blocks                           | 0           |  
  287. | Queries                                       | 10          |  
  288. | Questions                                     | 9           |  
  289. | Select_full_join                              | 0           |  
  290. | Select_full_range_join                        | 0           |  
  291. | Select_range                                  | 0           |  
  292. | Select_range_check                            | 0           |  
  293. | Select_scan                                   | 5           |  
  294. | Slave_heartbeat_period                        |             |  
  295. | Slave_last_heartbeat                          |             |  
  296. | Slave_open_temp_tables                        | 0           |  
  297. | Slave_received_heartbeats                     |             |  
  298. | Slave_retried_transactions                    |             |  
  299. | Slave_running                                 | OFF         |  
  300. | Slow_launch_threads                           | 0           |  
  301. | Slow_queries                                  | 0           |  
  302. | Sort_merge_passes                             | 0           |  
  303. | Sort_range                                    | 0           |  
  304. | Sort_rows                                     | 0           |  
  305. | Sort_scan                                     | 0           |  
  306. | Ssl_accept_renegotiates                       | 0           |  
  307. | Ssl_accepts                                   | 0           |  
  308. | Ssl_callback_cache_hits                       | 0           |  
  309. | Ssl_cipher                                    |             |  
  310. | Ssl_cipher_list                               |             |  
  311. | Ssl_client_connects                           | 0           |  
  312. | Ssl_connect_renegotiates                      | 0           |  
  313. | Ssl_ctx_verify_depth                          | 0           |  
  314. | Ssl_ctx_verify_mode                           | 0           |  
  315. | Ssl_default_timeout                           | 0           |  
  316. | Ssl_finished_accepts                          | 0           |  
  317. | Ssl_finished_connects                         | 0           |  
  318. | Ssl_server_not_after                          |             |  
  319. | Ssl_server_not_before                         |             |  
  320. | Ssl_session_cache_hits                        | 0           |  
  321. | Ssl_session_cache_misses                      | 0           |  
  322. | Ssl_session_cache_mode                        | NONE        |  
  323. | Ssl_session_cache_overflows                   | 0           |  
  324. | Ssl_session_cache_size                        | 0           |  
  325. | Ssl_session_cache_timeouts                    | 0           |  
  326. | Ssl_sessions_reused                           | 0           |  
  327. | Ssl_used_session_cache_entries                | 0           |  
  328. | Ssl_verify_depth                              | 0           |  
  329. | Ssl_verify_mode                               | 0           |  
  330. | Ssl_version                                   |             |  
  331. | Table_locks_immediate                         | 70          |  
  332. | Table_locks_waited                            | 0           |  
  333. | Table_open_cache_hits                         | 3           |  
  334. | Table_open_cache_misses                       | 67          |  
  335. | Table_open_cache_overflows                    | 0           |  
  336. | Tc_log_max_pages_used                         | 0           |  
  337. | Tc_log_page_size                              | 0           |  
  338. | Tc_log_page_waits                             | 0           |  
  339. | Threads_cached                                | 0           |  
  340. | Threads_connected                             | 1           |  
  341. | Threads_created                               | 1           |  
  342. | Threads_running                               | 1           |  
  343. | Uptime                                        | 167762      |  
  344. | Uptime_since_flush_status                     | 167762      |  
  345. +-----------------------------------------------+-------------+  
  346. 341 rows in set (0.00 sec)  

具体字段解释,参考mysql文档:

MySQL show status command: http://dev.mysql.com/doc/refman/5.1/en/show-status.html

MySQL server status: http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html

MySQL cluster status: http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-status-variables.html


0 0
原创粉丝点击