为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL参数最大连接数max_connections

标签:
MySQL

sConnectString = "Server=" + sServer + ";"

+ "database=" + sFileName + ";"

+ "Max Pool Size = 2048;"


+ "user id=" + sUId + ";"

+ "password=" + sPassword + ";";       //数据库连接串

1、查看最大连接数

mysql> show status like 'Threads%'; +-------------------+-------+ | Variable_name     | Value | +-------------------+-------+ | Threads_cached    | 58    | | Threads_connected | 57    |   ###这个数值指的是打开的连接数 | Threads_created   | 3676  | | Threads_running   | 4     |   ###这个数值指的是激活的连接数,这个数值一般远低于connected数值 +-------------------+-------+ Threads_connected 跟show processlist结果相同,表示当前连接数。准确的来说,Threads_running是代表当前并发数 这是是查询数据库当前设置的最大连接数 mysql> show variables like '%max_connections%'; +-----------------+-------+ | Variable_name   | Value | +-----------------+-------+ | max_connections | 1000  | +-----------------+-------+ 可以在/etc/my.cnf里面设置数据库的最大连接数 [mysqld] max_connections = 1000

2、show status

   Threads_connected  当前的连接数

   Connections  试图连接到(不管是否成功)MySQL服务器的连接数。

   Max_used_connections  服务器启动后已经同时使用的连接的最大数量。

3、设置最大连接数

set GLOBAL max_connections=2000; set GLOBAL max_user_connections=1500; mysql> show global variables like "max%connections"; +----------------------+-------+ | Variable_name        | Value | +----------------------+-------+ | max_connections      | 2000  | | max_user_connections | 1500  | +----------------------+-------+ 2 rows in set (0.08 sec)

说明,

系统支持的最大连接max_connections

用户能最大连接进来的数量max_user_connections

别忘记在配置文件里添加否则重启失效

max_connections=1000;

max_user_connection=600

以上设置,为自己和其他用户预留几个连接空闲

4、修改/etc/my.cnf中的max_connections


5、show processlist   显示当前正在执行的MySQL连接

6、mysqladmin -u<user> -p<pwd> -h<host> status

显示当前MySQL状态   Uptime: 13131  Threads: 1  Questions: 22  Slow queries: 0  Opens: 16  Flush tables: 1  Open tables: 1  Queries per second avg: 0.1   mysqladmin -u<user> -p<pwd> -h<host> extended-status   显示mysql的其他状态 +-----------------------------------+----------+ | Variable_name                     | Value    | +-----------------------------------+----------+ | Aborted_clients                   | 0        | | Aborted_connects               | 1        | | Binlog_cache_disk_use       | 0        | | Binlog_cache_use               | 0        | | Bytes_received                   | 1152   | | Bytes_sent                         | 10400 | | Com_admin_commands      | 0        | | Com_assign_to_keycache  | 0        | ............................................................. ............................................................. | Threads_cached                 | 2        | | Threads_connected            | 1        | | Threads_created                | 3        | | Threads_running                | 1        | | Uptime                                | 13509    | | Uptime_since_flush_status | 13509    | +-----------------------------------+----------+

7、遇到最大连接数处理

[推荐] 使用 mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪个目录下可以使用命令查找:whereis mysqladmin); mysqladmin flush-hosts -h392.168.x.x -Pxxxx -uroot -pxxxx;

8、OS ulimit参数

[root@emsc ~]# ulimit -n 65535

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消