Home Database Mysql Tutorial mysql 1040错误Too many connections_MySQL

mysql 1040错误Too many connections_MySQL

Jun 01, 2016 pm 01:50 PM
Revise parameter server connect mistake

你的服务器是不是出现这样的警告?

信息如下:

\

 

从官方文档知道linux上面编译安装的mysql默认的连接为100个,这样对于网站的需求来说是远远不够的。

mysql官方告诉我们需要修改max_connections的值,那么我们怎么去修改呢?有两种方法

1、修改配置文件文件

修改/etc/my.cnf这个文件,在[mysqld]中新增max_connections=N,如果你没有这个文件请从编译源码中的support-files文件夹中复制你所需要的*.cnf文件为到/etc/my.cnf。我使用的是my-medium.cnf,中型服务器配置。例如我的[mysqld]的内容如下

[mysqld]

port              = 3306

socket            = /tmp/mysql.sock

skip-locking

key_buffer = 160M

max_allowed_packet = 1M

table_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

max_connections=1000

由于对mysql还不是很熟悉,所以很多参数没有修改。哈哈。。

2、非使用mysqld脚本自动启动的用户。

修改$MYSQL_HOME/bin/mysqld_safe文件

例如:/usr/local/mysql/bin/mysqld_safe这个文件

grep -n 'max_connection' $MYSQL_HOME/bin/mysqld_safe

修改对应行号的max_connections参数值

以上方法为参考网上的做法写的。

方法二:

在PHP手册里面找关于mysql_connect和mysql_pconnect的资料,下面是在php手册中对这两个函数的描述:

 mysql_connect 函数原型:

     resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]])

返回:

     如果成功则返回一个MySQL 连接标识,失败则返回FALSE。

描述:

     mysql_connect() 建立一个到MySQL 服务器的连接。当没有提供可选参数时使用以下默认值:server = 'localhost:3306',username =

服务器进程所有者的用户名,password = 空密码。

    如果用同样的参数第二次调用mysql_connect(),将不会建立新连接,而将返回已经打开的连接标识。参数new_link 改变此行为并使

mysql_connect() 总是打开新的连接,甚至当mysql_connect() 曾在前面被用同样的参数调用过。参数client_flags 可以是以下常量的组合

:MYSQL_CLIENT_COMPRESS,MYSQL_CLIENT_IGNORE_SPACE 或者MYSQL_CLIENT_INTERACTIVE。

     注: new_link 参数自PHP 4.2.0 起可用。

         client_flags 参数自PHP 4.3.0 起可用。  

一旦脚本结束,到服务器的连接就会被关闭。除非之前已经调用了mysql_close() 来关闭它。

mysql_pconnect :

函数原型:

resource mysql_pconnect ( [string server [, string username [, string password [, int client_flags]]]])

返回:

如果成功则返回一个正的MySQL 持久连接标识符,出错则返回FALSE。

描述:

     mysql_pconnect() 建立一个到MySQL 服务器的连接。如果没有提供可选参数,则使用如下默认值:server = 'localhost:3306',

username = 服务器进程所有者的用户名,password = 空密码。client_flags 参数可以是以下常量的组合:MYSQL_CLIENT_COMPRESS,

MYSQL_CLIENT_IGNORE_SPACE 或者MYSQL_CLIENT_INTERACTIVE。

     server 参数也可以包括端口号,例如"hostname:port",或者是本机套接字的的路径,例如":/path/to/socket"。

     注: 对":port" 的支持是3.0B4 版添加的。

         对":/path/to/socket" 的支持是3.0.10 版添加的。                                            两者之间的区别 :

mysql_pconnect() 和mysql_connect() 非常相似,但有两个主要区别。

     首先,当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的(持久)连接,如果找到,则返回此连接标识而不打开新连接。

     其次,当脚本执行完毕后到SQL 服务器的连接不会被关闭,此连接将保持打开以备以后使用(mysql_close() 不会关闭由mysql_pconnect() 建立的连接)。

     可选参数client_flags 自PHP 4.3.0 版起可用。此种连接称为"持久的"。

 

     小结一下,要保证你的系统不会出现Too many connections 错误,需要注意两点:

     1.保证你的apache的最大进程数不超过mysql的最大连接数;

     2.不要在程序里面用过多mysql_pconnect连接到同一个数据库服务器(一个就够了).这需要好的编码习惯和规范.特别是不断的给系统增加

新的功能,如果不注重系统架构和编码规范,当系统的复杂度到了一定的程度,整个系统就变得无法维护了.出现问题的时候解决起来就很麻烦了.

解决方法是修改/etc/mysql/my.cnf,添加以下一行:

set-variable = max_connections=500

或在启动命令中加上参数max_connections=500

就是修改最大连接数,然后重启mysql.默认的连接数是100,太少了,所以容易出现如题错误

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1279
29
C# Tutorial
1257
24
Unable to complete operation (Error 0x0000771) Printer error Unable to complete operation (Error 0x0000771) Printer error Mar 16, 2024 pm 03:50 PM

If you encounter an error message when using your printer, such as the operation could not be completed (error 0x00000771), it may be because the printer has been disconnected. In this case, you can solve the problem through the following methods. In this article, we will discuss how to fix this issue on Windows 11/10 PC. The entire error message says: The operation could not be completed (error 0x0000771). The specified printer has been deleted. Fix 0x00000771 Printer Error on Windows PC To fix Printer Error the operation could not be completed (Error 0x0000771), the specified printer has been deleted on Windows 11/10 PC, follow this solution: Restart Print Spool

How to change the personal name in the group on DingTalk_How to modify the personal name in the group on DingTalk How to change the personal name in the group on DingTalk_How to modify the personal name in the group on DingTalk Mar 29, 2024 pm 08:41 PM

1. First open DingTalk. 2. Open the group chat and click the three dots in the upper right corner. 3. Find my nickname in this group. 4. Click to enter to modify and save.

Solution to Windows Update prompt Error 0x8024401c error Solution to Windows Update prompt Error 0x8024401c error Jun 08, 2024 pm 12:18 PM

Table of Contents Solution 1 Solution 21. Delete the temporary files of Windows update 2. Repair damaged system files 3. View and modify registry entries 4. Turn off the network card IPv6 5. Run the WindowsUpdateTroubleshooter tool to repair 6. Turn off the firewall and other related anti-virus software. 7. Close the WidowsUpdate service. Solution 3 Solution 4 "0x8024401c" error occurs during Windows update on Huawei computers Symptom Problem Cause Solution Still not solved? Recently, the web server needs to be updated due to system vulnerabilities. After logging in to the server, the update prompts error code 0x8024401c. Solution 1

How to configure Dnsmasq as a DHCP relay server How to configure Dnsmasq as a DHCP relay server Mar 21, 2024 am 08:50 AM

The role of a DHCP relay is to forward received DHCP packets to another DHCP server on the network, even if the two servers are on different subnets. By using a DHCP relay, you can deploy a centralized DHCP server in the network center and use it to dynamically assign IP addresses to all network subnets/VLANs. Dnsmasq is a commonly used DNS and DHCP protocol server that can be configured as a DHCP relay server to help manage dynamic host configurations in the network. In this article, we will show you how to configure dnsmasq as a DHCP relay server. Content Topics: Network Topology Configuring Static IP Addresses on a DHCP Relay D on a Centralized DHCP Server

Why does the Xiangxiangfuzhai app display an error? Why does the Xiangxiangfuzhai app display an error? Mar 19, 2024 am 08:04 AM

The display error is a problem that may occur in the Xiangxiang Fuzhai app. Some users are not sure why the Xiangxiang Fuzhai app displays errors. It may be due to network connection problems, too many background programs, incorrect registration information, etc. Next, This is the editor’s introduction to how to solve app display errors for users. Interested users should come and take a look! Why does the Xiangxiang Fuzhai app display an error answer: network connection problem, too many background programs, incorrect registration information, etc. Details: 1. [Network problem] Solution: Check the device connection network status, reconnect or choose another network connection to use. Can. 2. [Too many background programs] Solution: Close other running programs and release the system, which can speed up the running of the software. 3. [Incorrect registration information

Linux Oops: Detailed explanation of what this error means Linux Oops: Detailed explanation of what this error means Mar 21, 2024 am 09:06 AM

LinuxOops: Detailed explanation of the meaning of this error, need specific code examples What is LinuxOops? In Linux systems, "Oops" refers to a situation where a serious error in the kernel causes the system to crash. Oops is actually a kernel crash mechanism that stops the system when a fatal error occurs and prints out relevant error information so that developers can diagnose and fix the problem. Oops usually occur in kernel space and have nothing to do with user space applications. When the kernel encounters

Can Douyin Blue V change its name? What are the steps to change the name of corporate Douyin Blue V account? Can Douyin Blue V change its name? What are the steps to change the name of corporate Douyin Blue V account? Mar 22, 2024 pm 12:51 PM

Douyin Blue V certification is the official certification of a company or brand on the Douyin platform, which helps enhance brand image and credibility. With the adjustment of corporate development strategy or the update of brand image, the company may want to change the name of Douyin Blue V certification. So, can Douyin Blue V change its name? The answer is yes. This article will introduce in detail the steps to modify the name of the enterprise Douyin Blue V account. 1. Can Douyin Blue V change its name? You can change the name of Douyin Blue V account. According to Douyin’s official regulations, corporate Blue V certified accounts can apply to change their account names after meeting certain conditions. Generally speaking, enterprises need to provide relevant supporting materials, such as business licenses, organization code certificates, etc., to prove the legality and necessity of changing the name. 2. What are the steps to modify the name of corporate Douyin Blue V account?

How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset Mar 23, 2024 pm 01:16 PM

1. Place the earphones in the earphone box and keep the lid open. Press and hold the button on the box to enter the pairing state of the earphones. 2. Turn on the watch music function and select Bluetooth headphones, or select Bluetooth headphones in the watch settings function. 3. Select the headset on the watch to pair successfully.

See all articles