mysql MySqlConnection判断mysql是否连接成功and查看连接数和状态等

MySqlConnection conn = new MySqlConnection(connstr) //新建一个MySqlConnection数据库连接

1、mysql> show status like '%connect%';

   Connections,试图连接到(不管是否成功)MySQL服务器的连接数。
   Max_used_connections,服务器启动后已经同时使用的连接的最大数量。
   Threads_connected,当前的连接数。

2、mysql> show variables like '%connect%';

   max_connections,最大连接数。

3、修改max_connections

   在配置文件(my.cnf或my.ini)在最下面,天加一句:
   max_connections=32000
   然后,用命令重启:/etc/init.d/mysqld restart
   虽然这里写的32000,
实际MySQL服务器允许的最大连接数16384;
   添加了最大允许连接数,对系统消耗增加不大。

4、mysql> show processlist;
显示当前正在执行的MySQL连接。

[sql]  view plain  copy
  1. mysql> show status like '%connect%';  
  2. +-----------------------------------------------+---------+  
  3. | Variable_name                                 | Value   |  
  4. +-----------------------------------------------+---------+  
  5. | Aborted_connects                              | 45643   |  
  6. | Connection_errors_accept                      | 0       |  
  7. | Connection_errors_internal                    | 0       |  
  8. | Connection_errors_max_connections             | 2275689 |  
  9. | Connection_errors_peer_address                | 15      |  
  10. | Connection_errors_select                      | 0       |  
  11. | Connection_errors_tcpwrap                     | 0       |  
  12. | Connections                                   | 145379  |  
  13. | Max_used_connections                          | 152     |  
  14. | Performance_schema_session_connect_attrs_lost | 0       |  
  15. | Ssl_client_connects                           | 0       |  
  16. | Ssl_connect_renegotiates                      | 0       |  
  17. | Ssl_finished_connects                         | 0       |  
  18. | Threads_connected                             | 7       |  
  19. +-----------------------------------------------+---------+  
  20. 14 rows in set (0.00 sec)  
  21.   
  22. mysql> show variables like '%connect%';  
  23. +-----------------------------------------------+-----------------+  
  24. | Variable_name                                 | Value           |  
  25. +-----------------------------------------------+-----------------+  
  26. | character_set_connection                      | utf8            |  
  27. | collation_connection                          | utf8_general_ci |  
  28. | connect_timeout                               | 10              |  
  29. | disconnect_on_expired_password                | ON              |  
  30. | init_connect                                  |                 |  
  31. | max_connect_errors                            | 100             |  
  32. | max_connections                               | 151             |  
  33. | max_user_connections                          | 0               |  
  34. | performance_schema_session_connect_attrs_size | 512             |  
  35. +-----------------------------------------------+-----------------+  
  36. rows in set (0.00 sec)  
  37.   
  38. mysql> show processlist;  
  39. +--------+------+-----------------+------+---------+------+-------+------------------+  
  40. | Id     | User | Host            | db   | Command | Time | State | Info             |  
  41. +--------+------+-----------------+------+---------+------+-------+------------------+  
  42. | 145367 | root | localhost       | NULL | Query   |    0 | init  | show processlist |  
  43. | 145373 | root | localhost:58275 | push | Sleep   |  179 |       | NULL             |  
  44. | 145374 | root | localhost:58276 | push | Sleep   |  179 |       | NULL             |  
  45. | 145375 | root | localhost:58278 | push | Sleep   |  179 |       | NULL             |  
  46. | 145376 | root | localhost:58280 | push | Sleep   |    0 |       | NULL             |  
  47. | 145377 | root | localhost:58279 | push | Sleep   |    2 |       | NULL             |  
  48. | 145378 | root | localhost:58282 | push | Sleep   |    0 |       | NULL             |  
  49. +--------+------+-----------------+------+---------+------+-------+------------------+  
  50. rows in set (0.00 sec)  


你可能感兴趣的:(c#高级)