mysql数据库连接过多的错误_MySQL
统不能连接数据库,关键要看两个数据:
1、数据库系统允许的最大可连接数max_connections。这个参数是可以设置的。如果不设置,默认是100。最大是16384。
2、数据库当前的连接线程数threads_connected。这是动态变化的。
查看max_connections、max_connections的办法见后。
如果 threads_connected == max_connections 时,数据库系统就不能提供更多的连接数了,这时,如果程序还想新建连接线程,数据库系统就会拒绝,如果程序没做太多的错误处理,就会出现类似强坛的报错信息。
因为创建和销毁数据库的连接,都会消耗系统的资源。而且为了避免在同一时间同时打开过多的连接线程,现在编程一般都使用所谓数据库连接池技术。
但数据库连接池技术,并不能避免程序错误导致连接资源消耗殆尽。
这种情况通常发生在程序未能及时释放数据库连接资源或其他原因造成数据库连接资源不能释放,但强坛系统估计不会发生这种低级的编程错误。
该错误的简便的检查办法是,在刷新强坛页面时,不断监视threads_connected的变化。如果max_connections足够大,而 threads_connected值不断增加以至达到max_connections,那么,就应该检查程序了。当然,如果采用数据库连接池技术, threads_connected增长到数据库连接池的最大连接线程数时,就不再增长了。
从强坛出错的情况看,更大的可能性是数据库系统没能进行适当地配置。下面提出一点建议。供参考
让你们的工程师把MySQL的最大允许连接数从默认的100调成32000。这就不会老出现连接过多的问题了。
查看max_connections
进入MySQL,用命令:show variables
查看数据库最大可连接数的变量值:max_connections
查看threads_connected
进入MySQL,用命令:show status
查看当前活动的连接线程变量值:threads_connected
设置max_connections
设置办法是在my.cnf文件中,添加下面的最后红色的一行:
--------------------------------------------------------------------------------
[mysqld]
port=3306
#socket=MySQL
skip-locking
set-variable = key_buffer=16K
set-variable = max_allowed_packet=1M
set-variable = thread_stack=64K
set-variable = table_cache=4
set-variable = sort_buffer=64K
set-variable = net_buffer_length=2K
set-variable = max_connections=32000
--------------------------------------------------------------------------------
修改完毕后,重启MySQL即可。当然,为了确保设置正确,应该查看一下max_connections。
注意:
1、虽然这里写的32000。但实际MySQL服务器允许的最大连接数16384;
2、除max_connections外,上述其他配置应该根据你们系统自身需要进行配置,不必拘泥;
3、添加了最大允许连接数,对系统消耗增加不大。
4、如果你的mysql用的是my.ini作配置文件,设置类似,但设置的格式要稍作变通

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to implement database connection and transaction processing in FastAPI Introduction: With the rapid development of web applications, database connection and transaction processing have become a very important topic. FastAPI is a high-performance Python web framework loved by developers for its speed and ease of use. In this article, we will introduce how to implement database connections and transactions in FastAPI to help you build reliable and efficient web applications. Part 1: Database connection in FastA

How to use PHP database connection to implement paging query. When developing web applications, it often involves the need to query the database and perform paging display. As a commonly used server-side scripting language, PHP has powerful database connection functions and can easily implement paging queries. This article will introduce in detail how to use PHP database connection to implement paging query, and attach corresponding code examples. Prepare the database Before we start, we need to prepare a database containing the data to be queried. Here we take the MySQL database as an example,

For Nvidia's gaming graphics card, the most important thing is what games it can play, so friends who want to buy a 4050 graphics card are naturally curious about what games this graphics card can play. In fact, it should be able to play all games. . What games can the 4050 graphics card drive? Answer: The 4050 graphics card should be able to drive all computer games on the market. Its performance is at least comparable to the current 3060ti, and the 3060ti can drive all current PC games. (We will predict the performance of the 4050 from the 3060ti test below) 1. In terms of game testing, the 3060ti can maintain a stable 150fps or above at 1080p resolution. 2. Therefore, we directly test its performance at 2k resolution.

Common database connection and data reading and writing problems in C# require specific code examples. In C# development, database connection and data reading and writing are frequently encountered problems. Correct handling of these problems is the key to ensuring code quality and performance. This article will introduce some common database connection and data reading and writing problems, and provide specific code examples to help readers better understand and solve these problems. Database connection issues 1.1 Connection string errors When connecting to the database, a common error is that the connection string is incorrect. The connection string contains the connection to the database

Reasons for a PHP database connection failure include: the database server is not running, incorrect hostname or port, incorrect database credentials, or lack of appropriate permissions. Solutions include: starting the server, checking the hostname and port, verifying credentials, modifying permissions, and adjusting firewall settings.

Advanced PHP database connections involve transactions, locks, and concurrency control to ensure data integrity and avoid errors. A transaction is an atomic unit of a set of operations, managed through the beginTransaction(), commit(), and rollback() methods. Locks prevent simultaneous access to data via PDO::LOCK_SHARED and PDO::LOCK_EXCLUSIVE. Concurrency control coordinates access to multiple transactions through MySQL isolation levels (read uncommitted, read committed, repeatable read, serialized). In practical applications, transactions, locks and concurrency control are used for product inventory management on shopping websites to ensure data integrity and avoid inventory problems.

How to configure database connection in mybatis: 1. Specify the data source; 2. Configure the transaction manager; 3. Configure the type processor and mapper; 4. Use environment elements; 5. Configure aliases. Detailed introduction: 1. Specify the data source. In the "mybatis-config.xml" file, you need to configure the data source. The data source is an interface, which provides a database connection; 2. Configure the transaction manager to ensure the normality of database transactions. For processing, you also need to configure the transaction manager; 3. Configure the type processor and mapper, etc.

How to connect and operate the database and process SQL queries. In the process of developing applications, database connection and operation are a very important part. Database is an important tool for storing and managing data, and SQL (StructuredQueryLanguage) is a standard language for querying and operating databases. In this article, we will learn how to connect to and operate a database and show some code examples for handling SQL queries. Connect to the database: First, we need to connect to the database to proceed
