mysql优化配置参数
mysql安装好需要优化配置一下,打开c:\windows\my.ini文件
第一种代码如下:
#This File was made using the WinMySQLAdmin 1.4 Tool
#2004-2-23 16:28:14
#Uncomment or Add only the keys that you know how works.
#Read the MySQL Manual for instructions
[mysqld]
basedir=D:/mysql
#bind-address=210.5.*.*
datadir=D:/mysql/data
#language=D:/mysql/share/your language directory
#slow query log#=
#tmpdir#=
#port=3306
set-variable = max_connections=1500
skip-locking
#skip-networking
set-variable = key_buffer=384M
set-variable = max_allowed_packet=1M
set-variable = table_cache=512
set-variable = sort_buffer=2M
set-variable = record_buffer=2M
set-variable = thread_cache=8
# Try number of CPU's*2 for thread_concurrency
set-variable = thread_concurrency=8
set-variable = myisam_sort_buffer_size=64M
#set-variable = connect_timeout=5
#set-variable = wait_timeout=5
server-id = 1
[isamchk]
set-variable = key_buffer=128M
set-variable = sort_buffer=128M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[myisamchk]
set-variable = key_buffer=128M
set-variable = sort_buffer=128M
set-variable = read_buffer=2M
set-variable = write_buffer=2M
[WinMySQLadmin]
Server=D:/mysql/bin/mysqld-nt.exe
这个方案,整体够用了,但是在pconnect和最大连接数上,需要研究max_connections没必要那么大,我个人认为几百就够,否则给服务器加大了不少负担,经常会当机连接超时的设置也要根据实际情况调整,大家可以自由调整,然后观察效果如何。
第二种
7、MYSQL 的优化(/etc/my.cnf)
1)确认在“[mysqld]”部分加入了“skip-innodb”和“skip-bdb”参数;
2)确认在“[mysqld]”部分加入了“skip-name-resolve”和“skip-locking”参数;
3)如果不需要的话,可以将二进制日志(binlog)停掉,方法是将“log-bin”注释掉;
4)在内存允许的情况下,对一些参数进行重新配置,目标在于将大部分操作集中于内存中,尽量不进行磁盘操作,对于我的 MYSQL 服务器我是如下修改的,基于 2G 内存情况:
代码如下:
[mysqld]
set-variable = key_buffer=512M
set-variable = max_allowed_packet=4M
set-variable = table_cache=1024
set-variable = thread_cache=64
set-variable = join_buffer_size=32M
set-variable = sort_buffer=32M
set-variable = record_buffer=32M
set-variable = max_connections=512
set-variable = wait_timeout=120
set-variable = interactive_timeout=120
set-variable = max_connect_errors=30000
set-variable = long_query_time=1
set-variable = max_heap_table_size=256M
set-variable = tmp_table_size=128M
set-variable = thread_concurrency=8
set-variable = myisam_sort_buffer_size=128M
你可以根据“show status”命令返回的状态进行微调。我主要注意以下变量的数值,越小越好,最好为零:)
Created_tmp_disk_tables
Created_tmp_tables
Created_tmp_files
Slow_queries
另外 mysql wait_timeout 那个值设置大了没用 做10左右就可了 (大C说得)
wait_timeout是使用长久连线时 空闲进程的控制只要数据库在连接状态 他是不进行干预的 不管是否有查询或更新操作把这个设置小一点 再使用pconnect就比较理想了 ;)
timeout的時間﹐我的經驗值是5-20﹐看你的SERVER的訪問量了~~ (梦飞说的)
访问量越大 这个值就应该越小否则留出的空闲进程太多 会占用不必要的内存
在一个15分钟在线3000人的论坛上 设置为3比较合适同时打开pconnect
第三种
数据库连接过多的错误,可能的原因分析及解决办法
分析
系统不能连接数据库,关键要看两个数据:
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作配置文件,设置类似,但设置的格式要稍作变通。
可见,mysql的优化,是多样化,且根据环境不同,必须灵活调整的,大家不可生搬硬套,自己慢慢体会吧

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

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

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











Asus Slugger bios settings for best performance? Factory settings for optimal performance. The specific method is: 1. Press F2 while turning on the computer to enter the BIOS. 2. In the Boot menu, set secure to disabled. 3. Set BootListOption to UEFI. 4. In 1stBootPriority, HDD (hard disk) is the first boot item. 5. Select Savechangesandreset in the Exit menu or press F10 to save and exit. What are the best settings for ASUS x670ehero motherboard bios? To get the best ASUS x670ehero motherboard bios settings, you need to adjust them according to your own hardware configuration and usage needs. First, set it up correctly

On April 10, Canon (China) Co., Ltd. launched the CJ27e×7.3BIASET, a 4K broadcast-grade portable zoom lens equipped with a newly developed digital drive unit "e-XsV", suitable for 2/3-inch 4K broadcast-grade cameras. The lens has excellent optical performance and can achieve a wide angle and high zoom ratio. It inherits the excellent operating feel brought by the ergonomic design while improving ease of use and functionality. The launch of this lens further broadens the shooting application scenarios to meet the diverse shooting needs of users. The usage scenarios include not only live broadcasts and news reports, but also studio program recording and remote video production that require the use of special shooting equipment. Digital drive unit "e-XsV" CJ27e×7.3B takes care of 7.

With the continuous development of the Internet, more and more applications and businesses require the use of programs developed in the Java language. For the running of Java programs, the performance of the Java Virtual Machine (JVM) is very important. Therefore, optimizing configuration is an important means to improve the performance of Java applications. Pagoda panel is a commonly used server control panel that can help users manage servers more conveniently. This article will introduce how to use the Pagoda panel to optimize the configuration of the Java virtual machine. Step one: Install Java virtual machine

Use caching: Using caching mechanisms can significantly improve website performance. You can use CodeIgniter's built-in caching class or a third-party caching library, such as Memcached or Redis, to implement the caching function. Optimize queries: Make sure your SQL queries are efficient and make good use of indexes. This will help your database return results quickly, resulting in faster page loads. Use fewer PHP objects: Creating PHP objects requires some overhead, so try to avoid creating too many objects if you don’t need them. This will help reduce memory consumption and speed up script execution. Use fewer function calls: Too many function calls increase the execution time of your script. If you can combine multiple function calls into one, doing so will improve

PHP mailbox development: Optimizing the configuration and management of mail servers In modern society, email has become an indispensable part of people's daily life and work. For PHP developers, providing users with complete email functions is an important task. To achieve an efficient and stable mailbox system, optimizing the configuration and management of the mail server is a crucial link. 1. Selection of operating environment Before starting to configure and manage the mail server, we must first select an appropriate operating environment. Common mail servers include S

Improving Python programming efficiency: Computer configuration optimization methods In modern programming work, Python has become a very popular programming language. Not only because of its concise and easy-to-learn syntax, but also because of its powerful ecosystem and rich third-party library support. However, even using an efficient tool like Python, we can further improve programming efficiency by optimizing computer configuration. This article will introduce some computer configuration optimization methods to improve Python programming efficiency, and provide specific code examples. 1. Hardware configuration

CentOS Platform HDFS Cluster Performance Optimization Guide This article explains how to optimize HDFS configuration on CentOS system and improve cluster performance. The optimization process covers multiple aspects and needs to be adjusted according to actual needs and hardware environment. It is recommended to verify the effectiveness of any significant changes in the production environment before implementing its data. 1. Simplified installation of system basic configuration: adopt a minimal installation method, install only necessary software packages to reduce system resource consumption. Network settings: Ensure that the network configuration is correct, it is recommended to use a static IP address and reasonably configure network parameters to ensure network stability and high-speed transmission. 2. HDFS core parameter tuning core configuration file: Correctly configure core-site.xml

Optimizing the performance and stability of SpringBoot and Kafka Introduction SpringBoot and Kafka are two very popular open source frameworks that can help developers quickly build and deploy distributed systems. SpringBoot provides tools to simplify Spring application development, while Kafka is a distributed messaging system that can reliably store and process large amounts of data. By optimizing the performance and stability of SpringBoot and Kafka
