MySQL服务器5.1configuration2008年胜利(专家帮助需要)

我在win 2008 R2 x64标准版上运行MySql server 5.1.52-community。 其生产服务器。 当应用层“另一个服务器”引入太多的请求/ tcp连接/“每秒超过2000个查询”时,应用层停止。

应用层是很多企业使用的非常稳定的企业产品。 支持团队明确表示数据库服务器有问题。

所以我调整了MySQLconfiguration很多次,仍然在重载的情况下,应用程序层停止。

该服务器有16 GB的内存,但MySQL只使用约5 GB。 所以第一个问题是如何让MySQL服务器服务使用高达12 GB。

我注意到的一件奇怪的事情是,mysqld进程有超过一百万个句柄“1,114,345”,这是非常不正常的,其中任何正常进程得到最多2000句柄! 所以专家是好的! 如果没有,那么如何解决这个问题。

该数据库是没有视图或SP的innoDB。

请帮忙,谢谢,

编辑 :看着专家的意见后,这里是目前的MySQLconfiguration:

[client] port=3306 [mysql] default-character-set=utf8 # SERVER SECTION # ---------------------------------------------------------------------- # # The following options will be read by the MySQL Server. Make sure that # you have installed the server correctly (see above) so it reads this # file. # [mysqld] # The TCP/IP Port the MySQL Server will listen on port=3306 #Path to installation directory. All paths are usually resolved relative to this. basedir="C:/Autonomy/MySQL/" #Path to the database root datadir="D:/MySQL Datafiles/data/" # The default character set that will be used when a new schema or table is # created and no character set is defined default-character-set=utf8 # The default storage engine that will be used when create new tables when default-storage-engine=INNODB # Set the SQL mode to strict sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" # The maximum amount of concurrent sessions the MySQL server will # allow. One of these connections will be reserved for a user with # SUPER privileges to allow the administrator to login even if the # connection limit has been reached. max_connections=400 # Query cache is used to cache SELECT results and later return them # without actual executing the same query once again. Having the query # cache enabled may result in significant speed improvements, if your # have a lot of identical queries and rarely changing tables. See the # "Qcache_lowmem_prunes" status variable to check if the current value # is high enough for your load. # Note: In case your tables change very often or if your queries are # textually different every time, the query cache may result in a # slowdown instead of a performance improvement. query_cache_size=84M # The number of open tables for all threads. Increasing this value # increases the number of file descriptors that mysqld requires. # Therefore you have to make sure to set the amount of open files # allowed to at least 4096 in the variable "open-files-limit" in # section [mysqld_safe] table_cache=256 # Maximum size for internal (in-memory) temporary tables. If a table # grows larger than this value, it is automatically converted to disk # based table This limitation is for a single table. There can be many # of them. tmp_table_size=369M # How many threads we should keep in a cache for reuse. When a client # disconnects, the client's threads are put in the cache if there aren't # more than thread_cache_size threads from before. This greatly reduces # the amount of thread creations needed if you have a lot of new # connections. (Normally this doesn't give a notable performance # improvement if you have a good thread implementation.) thread_cache_size=8 #*** MyISAM Specific options # The maximum size of the temporary file MySQL is allowed to use while # recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE. # If the file-size would be bigger than this, the index will be created # through the key cache (which is slower). myisam_max_sort_file_size=100G # If the temporary file used for fast index creation would be bigger # than using the key cache by the amount specified here, then prefer the # key cache method. This is mainly used to force long character keys in # large tables to use the slower key cache method to create the index. myisam_sort_buffer_size=738M # Size of the Key Buffer, used to cache index blocks for MyISAM tables. # Do not set it larger than 30% of your available memory, as some memory # is also required by the OS to cache rows. Even if you're not using # MyISAM tables, you should still set it to 8-64M as it will also be # used for internal temporary disk tables. key_buffer_size=320M # Size of the buffer used for doing full table scans of MyISAM tables. # Allocated per thread, if a full scan is needed. read_buffer_size=64K read_rnd_buffer_size=256K # This buffer is allocated when MySQL needs to rebuild the index in # REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE # into an empty table. It is allocated per thread so be careful with # large settings. sort_buffer_size=256K #*** INNODB Specific options *** innodb_data_home_dir="D:/MySQL Datafiles/" # Use this option if you have a MySQL server with InnoDB support enabled # but you do not plan to use it. This will save memory and disk space # and speed up some things. #skip-innodb # Additional memory pool that is used by InnoDB to store metadata # information. If InnoDB requires more memory for this purpose it will # start to allocate it from the OS. As this is fast enough on most # recent operating systems, you normally do not need to change this # value. SHOW INNODB STATUS will display the current amount used. innodb_additional_mem_pool_size=26M # If set to 1, InnoDB will flush (fsync) the transaction logs to the # disk at each commit, which offers full ACID behavior. If you are # willing to compromise this safety, and you are running small # transactions, you may set this to 0 or 2 to reduce disk I/O to the # logs. Value 0 means that the log is only written to the log file and # the log file flushed to disk approximately once per second. Value 2 # means the log is written to the log file at each commit, but the log # file is only flushed to disk approximately once per second. innodb_flush_log_at_trx_commit=2 # The size of the buffer InnoDB uses for buffering log data. As soon as # it is full, InnoDB will have to flush it to disk. As it is flushed # once per second anyway, it does not make sense to have it very large # (even with long transactions). innodb_log_buffer_size=13M # InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and # row data. The bigger you set this the less disk I/O is needed to # access data in tables. On a dedicated database server you may set this # parameter up to 80% of the machine physical memory size. Do not set it # too large, though, because competition of the physical memory may # cause paging in the operating system. Note that on 32bit systems you # might be limited to 2-3.5G of user level memory per process, so do not # set it too high. #innodb_buffer_pool_size=1243M innodb_buffer_pool_size=4096M # Size of each log file in a log group. You should set the combined size # of log files to about 25%-100% of your buffer pool size to avoid # unneeded buffer pool flush activity on log file overwrite. However, # note that a larger logfile size will increase the time needed for the # recovery process. innodb_log_file_size=622M # Number of threads allowed inside the InnoDB kernel. The optimal value # depends highly on the application, hardware as well as the OS # scheduler properties. A too high value may lead to thread thrashing. innodb_thread_concurrency=18 #Enter a name for the query log file. Otherwise a default name will be used. # incase of remove command # for log sql queries will be logged #log #innod table extend innodb_data_file_path=ibdata1:18M;inno_db_001:400M:autoextend #innodb_log_group_home_dir="D:/MySQL Datafiles/" lower_case_table_names=1 innodb_file_io_threads=4 innodb_lock_wait_timeout=50 #replication configuration log-bin=mysql-bin server-id = 1 

所以我想如果我改变了:
innodb_buffer_pool_size = 4096M

innodb_buffer_pool_size = 12G
12GB将分配给mysqld服务/进程。 对?? 还有什么应该改变?

我还发现,如果查询超过15分钟,应用程序将认为它尝试失败,虽然MySQL仍然在取得它! 也许这是什么导致手柄变得非常大!
我也想一些查询必须从映射的networking驱动器读取。 但没有什么可以做的改变这一点。 完全不受我的控制。

有时手柄可能是一个真正的头痛。 我通常和客户一起处理这个问题是一个快捷的创可贴解决scheme:运行这个命令:

 FLUSH TABLES; 

这将closures所有桌子上的打开手柄并将其打开。 我相信没有正确closures的把手会消失,特别是当一个表有几十个把手打开,只有一个或两个实际使用。 我已经看了手柄放在MONYOG图表,我跑了这个后,我已经build立了。

您可能正在运行查询,看起来很正常,其EXPLAIN计划什么都不告诉你。 但是,将足够的疑问放在一起,单独堆放打开的手柄,您就可以体验比处于closures状态的手柄开放速度更快的竞争条件。 可见的净效应是很多条目进入慢查询日志,其查询在独立执行时工作正常。 此外,您将储存查询,只是旋转他们的轮子执行复制临时表或一些间歇性sorting。

这是Handles的一个示例状态variables

Handler_read_last : 读取索引中最后一个键的请求数。 使用ORDER BY,服务器将发出第一个关键字请求,然后是几个next-key请求,而使用WITH ORDER BY DESC,服务器将发出最后一个关键字请求,然后是几个先前的关键字请求。 这个variables是在MySQL 5.5.7中添加的。

现在这个在MySQL 5.1.52中不存在,但是这里有一个问题:你有执行ORDER BY … DESC的查询吗? 如果你这样做,那么你希望你有Handler_read_last。 既然你不这样做,MySQL会用ORDER BY … DESC做什么? 它将遍历整个索引到最后一行,收集键和sorting。 在你的应用程序中是否有很多这种性质的查询? ( 问题为您的研究

这是Handles的另一个状态variables:

Handler_read_first : 读取索引中第一个条目的次数。 如果这个值很高,则表明服务器正在进行大量的索引扫描; 例如,SELECT col1 FROM foo,假定col1被索引。

你的研究的另一个问题 :你有很多的查询执行完整的索引扫描?

另一个猜测:检查你的open_files_limitinnodb_open_files 。 如果打开的文件数量上限正在生成新的句柄并留下其他句柄,则可能需要增加其中一个或两个。

mysqld进程已经超过一百万个处理“1,114,345”

看起来很高。

查询超过15分钟的应用程序将认为它失败的尝试,虽然MySQL仍然在提取它的工作!

ERK。

你没有configuration为MySQL的超时?

什么是逻辑层在做什么? 它使用持续连接吗? 你可以切换到非持久性?

我认为一些查询必须从映射的networking驱动器读取

FFS! 如果数据必须存在于单独的服务器上,那么在该服务器上运行MySQL并使用联合驱动程序或集群复制。 这是唯一的方法(除了iscsi之外,它并不真正适合在文件系统之上运行),以使其performance得像一个精心devise的系统。

一旦你解决了远程驱动问题,我build议:

1)如果可能,使用非持久连接

2)查询调优 – 如果你的查询速度足够快,这不会是一个问题。 我使用一些自制脚本以及这些Perl代码来确定需要什么工作。

3)对你的服务器运行mysqltuner.pl(也使用perl)。

这里有一个免费的MSWindows perl实现