Wishlist 0 ¥0.00

mysql优化(连接数、最大并发数)

目录

1、max_connections最大连接数

1.1、查询数据库当前设置的最大连接数

1.2、调整max_connections参数的值

1.2.1、方式一:实时(临时)修改此参数的值

1.2.2、方式二:在配置文件my.ini中设置max_connections的值

2、max_used_connections 查看最大连接数

3、max_user_connections 每个MySQL用户的最大连接数

3.1、查看全局每个用户最大连接数max_user_connections

 3.2、设置全局每个用户最大连接数max_user_connections

3.3、 针对某个用户进行最大连接数限制

4、mysql服务器的线程数 

4.1、查看mysql的线程情况

4.2、thread_cache_size缓存线程 优化

4,2.1、查询thread_cache_size

4.2.2、设置线程缓存数量 thread_cache_size


 

  1.  
    -- 查看最大连接数
  2.  
    show variables like '%max_connection%'
  3.  
     
  4.  
    -- 重新设置最大连接数
  5.  
    set global max_connections=700;   
  6.  
     
  7.  
    -- 查看数据库状态
  8.  
    -- threads_created:表示创建过的线程数,threads_created过大,
  9.  
    -- 表明mysql服务器一直在创建线程,这也是比较耗资源,说明服务器不健康。
  10.  
    show status like  'Threads%';
  11.  
     
  12.  
    -- 查询服务器 thread_cache_size 配置
  13.  
    show variables like 'thread_cache_size';
  14.  
    -- 设置 线程缓存数量
  15.  
    set global thread_cache_size=100;

1、max_connections最大连接数

1.1、查询数据库当前设置的最大连接数

show variables like '%max_connections%';

MySQL无论如何都会保留一个用于管理员(SUPER)登陆的连接,用于管理员连接数据库进行维护操作,即使当前连接数已经达到了max_connections。因此MySQL的实际最大可连接数为max_connections+1;
 这个参数实际起作用的最大值(实际最大可连接数)为16384,即该参数最大值不能超过16384,即使超过也以16384为准;

增加max_connections参数的值,不会占用太多系统资源。系统资源(CPU、内存)的占用主要取决于查询的密度、效率等

该参数设置过小的最明显特征是出现”Too many connections”错误;

MySQL比较理想的最大连接数计算方式为max_used_connections / max_connections*100% ≈ 85%

最大连接数占上限连接数的85%左右,如果发现比例在10%以下,MySQL服务器连接数上限设置的过高了。

1.2、调整max_connections参数的值

1.2.1、方式一:实时(临时)修改此参数的值

使用root用户登录。

set global max_connections=1000;   

修改完成后实时生效,无需重启MySQL。

总体来说,该参数在服务器资源够用的情况下应该尽量设置大,以满足多个客户端同时连接的需求。否则将会出现类似”Too many connections”的错误。

1.2.2、方式二:在配置文件my.ini中设置max_connections的值

找到max_connections一行,修改为(如果没有,则自己添加)1000.

About Us

Since 1996, our company has been focusing on domain name registration, web hosting, server hosting, website construction, e-commerce and other Internet services, and constantly practicing the concept of "providing enterprise-level solutions and providing personalized service support". As a Dell Authorized Solution Provider, we also provide hardware product solutions associated with the company's services.
 

Contact Us

Address: No. 2, Jingwu Road, Zhengzhou City, Henan Province

Phone: 0086-371-63520088 

QQ:76257322

Website: 800188.com

E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.