Home Database Mysql Tutorial 简单实现MySQL服务器的优化配置

简单实现MySQL服务器的优化配置

Jun 07, 2016 pm 04:13 PM
mysql main optimization accomplish article server Simple Configuration

以下的文章主要介绍的是对MySQL服务器的优化配置的时机操作步骤,同时本文也介绍了MySQL服务器的优化配置的实际应用代码,如果你对其相关的实际应用感兴趣的话,你就可以点击以下的文章对其进行了解。 你能用这个命令得到MySQL服务器缺省缓冲区大小: shell

以下的文章主要介绍的是对MySQL服务器的优化配置的时机操作步骤,同时本文也介绍了MySQL服务器的优化配置的实际应用代码,如果你对其相关的实际应用感兴趣的话,你就可以点击以下的文章对其进行了解。

你能用这个命令得到MySQL服务器缺省缓冲区大小:

shell> MySQL(和PHP搭配之最佳组合)d --help

这个命令生成一张所有MySQL(和PHP搭配之最佳组合)d选项和可配置变量的表。输出包括缺省值并且看上去象这样一些东西:

Possible variables for option --set-variable (-O) are:

<ol class="dp-xml">
<li class="alt"><span><span>back_log current value: 5   </span></span></li>
<li><span>connect_timeout current value: 5   </span></li>
<li class="alt"><span>delayed_insert_timeout current value: 300   </span></li>
<li><span>delayed_insert_limit current value: 100   </span></li>
<li class="alt"><span>delayed_queue_size current value: 1000   </span></li>
<li><span>flush_time current value: 0   </span></li>
<li class="alt"><span>interactive_timeout current value: 28800   </span></li>
<li><span>join_buffer_size current value: 131072   </span></li>
<li class="alt"><span>key_buffer_size current value: 1048540   </span></li>
<li><span>lower_case_table_names current value: 0   </span></li>
<li class="alt"><span>long_query_time current value: 10   </span></li>
<li><span>max_allowed_packet current value: 1048576   </span></li>
<li class="alt"><span>max_connections current value: 100   </span></li>
<li><span>max_connect_errors current value: 10   </span></li>
<li class="alt"><span>max_delayed_threads current value: 20   </span></li>
<li><span>max_heap_table_size current value: 16777216   </span></li>
<li class="alt"><span>max_join_size current value: 4294967295   </span></li>
<li><span>max_sort_length current value: 1024   </span></li>
<li class="alt"><span>max_tmp_tables current value: 32   </span></li>
<li><span>max_write_lock_count current value: 4294967295   </span></li>
<li class="alt"><span>net_buffer_length current value: 16384   </span></li>
<li><span>query_buffer_size current value: 0   </span></li>
<li class="alt"><span>record_buffer current value: 131072   </span></li>
<li><span>sort_buffer current value: 2097116   </span></li>
<li class="alt"><span>table_cache current value: 64   </span></li>
<li><span>thread_concurrency current value: 10   </span></li>
<li class="alt"><span>tmp_table_size current value: 1048576   </span></li>
<li><span>thread_stack current value: 131072   </span></li>
<li class="alt"><span>wait_timeout current value: 28800  </span></li>
</ol>
Copy after login

如果有一个MySQL服务器正在运行,通过执行这个命令,你可以看到它实际上使用的变量的值:

<ol class="dp-xml"><li class="alt">shell> MySQL(和PHP搭配之最佳组合)admin variables  </li></ol>
Copy after login

每个选项在下面描述。对于缓冲区大小、长度和栈大小的值以字节给出,你能用于个后缀“K”或“M” 指出以K字节或兆字节显示值。例如,16M指出16兆字节。后缀字母的大小写没有关系;16M和16m是相同的。

你也可以用命令SHOW STATUS自一个运行的服务器看见一些统计。见7.21 SHOW语法(得到表、列的信息)。

back_log

要求MySQL(和PHP搭配之最佳组合)能有的连接数量。当主要MySQL(和PHP搭配之最佳组合)线程在一个很短时间内得到非常多的连接请求,这就起作用,然后主线程花些时间(尽管很短)检查连接并且启动一个新线程。back_log值指出在MySQL(和PHP搭配之最佳组合)暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中。只有如果期望在一个短时间内有很多连接,你需要增加它,换句话说,这值对到来的TCP/IP连接的侦听队列的大小。你的操作系统在这个队列大小上有它自己的限制。 Unix listen(2)系统调用的手册页应该有更多的细节。检查你的OS文档找出这个变量的最大值。试图设定back_log高于你的操作系统的限制将是无效的。

connect_timeout

MySQL(和PHP搭配之最佳组合)d服务器在用Bad handshake(糟糕的握手)应答前正在等待一个连接报文的秒数。

delayed_insert_timeout

一个INSERT DELAYED线程应该在终止之前等待INSERT语句的时间。

delayed_insert_limit

在插入delayed_insert_limit行后,INSERT DELAYED处理器将检查是否有任何SELECT语句未执行。如果这样,在继续前执行允许这些语句。

delayed_queue_size

应该为处理INSERT DELAYED分配多大一个队列(以行数)。如果排队满了,任何进行INSERT DELAYED的客户将等待直到队列又有空间了。

flush_time

如果这被设置为非零值,那么每flush_time秒所有表将被关闭(以释放资源和sync到磁盘)。

interactive_timeout

MySQL服务器在关上它前在一个交互连接上等待行动的秒数。一个交互的客户被定义为对MySQL(和PHP搭配之最佳组合)_real_connect()使用CLIENT_INTERACTIVE选项的客户。也可见wait_timeout。

join_buffer_size

用于全部联结(join)的缓冲区大小(不是用索引的联结)。缓冲区对2个表间的每个全部联结分配一次缓冲区,当增加索引不可能时,增加该值可得到一个更快的全部联结。(通常得到快速联结的最佳方法是增加索引。)

key_buffer_size

索引块是缓冲的并且被所有的线程共享。key_buffer_size是用于索引块的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写),到你能负担得起那样多。如果你使它太大,系统将开始换页并且真的变慢了。记住既然MySQL(和PHP搭配之最佳组合)不缓存读取的数据,你将必须为OS文件系统缓存留下一些空间。为了在写入多个行时得到更多的速度,使用LOCK TABLES。见7.24LOCK TABLES/UNLOCK TABLES语法。

long_query_time

如果一个查询所用时间超过它(以秒计),Slow_queries记数器将被增加。

max_allowed_packet

一个包的最大尺寸。消息缓冲区被初始化为net_buffer_length字节,但是可在需要时增加到max_allowed_packet个字节。缺省地,该值太小必能捕捉大的(可能错误)包。如果你正在使用大的BLOB列,你必须增加该值。它应该象你想要使用的最大BLOB的那么大。

max_connections

允许的同时客户的数量。增加该值增加MySQL(和PHP搭配之最佳组合)d要求的文件描述符的数量。见下面对文件描述符限制的注释。见18.2.4 Too many connections错误。

max_connect_errors

如果有多于该数量的从一台主机中断的连接,这台主机阻止进一步的连接。你可用FLUSH HOSTS命令疏通一台主机。

max_delayed_threads

不要启动多于的这个数字的线程来处理INSERT DELAYED语句。如果你试图在所有INSERT DELAYED线程在用后向一张新表插入数据,行将被插入,就像DELAYED属性没被指定那样。

max_join_size

可能将要读入多于max_join_size个记录的联结将返回一个错误。如果你的用户想要执行没有一个WHERE子句、花很长时间并且返回百万行的联结,设置它。

max_sort_length

在排序BLOB或TEXT值时使用的字节数(每个值仅头max_sort_length个字节被使用;其余的被忽略)。

max_tmp_tables

(该选择目前还不做任何事情)。一个客户能同时保持打开的临时表的最大数量。

net_buffer_length

通信缓冲区在查询之间被重置到该大小。通常这不应该被改变,但是如果你有很少的内存,你能将它设置为查询期望的大小。(即,客户发出的SQL语句期望的长度。如果语句超过这个长度,缓冲区自动地被扩大,直到max_allowed_packet个字节。)

record_buffer

每个进行一个顺序扫描的线程为其扫描的每张表分配这个大小的一个缓冲区。如果你做很多顺序扫描,你可能想要增加该值。

sort_buffer

每个需要进行排序的线程分配该大小的一个缓冲区。增加这值加速ORDER BY或GROUP BY操作。见18.5 MySQL(和PHP搭配之最佳组合)在哪儿存储临时文件。

table_cache

为所有线程打开表的数量。增加该值能增加MySQL(和PHP搭配之最佳组合)d要求的文件描述符的数量。MySQL(和PHP搭配之最佳组合)对每个唯一打开的表需要2个文件描述符,见下面对文件描述符限制的注释。对于表缓存如何工作的信息,见10.2.4 MySQL(和PHP搭配之最佳组合)怎样打开和关闭表。

tmp_table_size

如果一张临时表超出该大小,MySQL(和PHP搭配之最佳组合)产生一个The table tbl_name is full形式的错误,如果你做很多高级GROUP BY查询,增加tmp_table_size值。

thread_stack

每个线程的栈大小。由crash-me测试检测到的许多限制依赖于该值。缺省队一般的操作是足够大了。见10.8 使用你自己的基准。

wait_timeout

MySQL服务器在关闭它之前在一个连接上等待行动的秒数。也可见interactive_timeout。

MySQL(和PHP搭配之最佳组合)使用是很具伸缩性的算法,因此你通常能用很少的内存运行或给MySQL(和PHP搭配之最佳组合)更多的被存以得到更好的性能。

如果你有很多内存和很多表并且有一个中等数量的客户,想要最大的性能,你应该一些象这样的东西:

<ol class="dp-xml">
<li class="alt">shell> safe_MySQL<span>(和PHP搭配之最佳组合)d -O </span><span class="attribute">key_buffer</span><span>=</span><span class="attribute-value">16M</span><span> -O </span><span class="attribute">table_cache</span><span>=</span><span>128 \   </span>
</li>
<li>
<span>-O </span><span class="attribute">sort_buffer</span><span>=</span><span class="attribute-value">4M</span><span> -O </span><span class="attribute">record_buffer</span><span>=</span><span class="attribute-value">1M</span><span> &  </span>
</li>
</ol>
Copy after login

如果你有较少的内存和大量的连接,使用这样一些东西:

<ol class="dp-xml">
<li class="alt">shell> safe_MySQL<span>(和PHP搭配之最佳组合)d -O </span><span class="attribute">key_buffer</span><span>=</span><span class="attribute-value">512k</span><span> -O </span><span class="attribute">sort_buffer</span><span>=</span><span>100k \   </span>
</li>
<li>
<span>-O </span><span class="attribute">record_buffer</span><span>=</span><span class="attribute-value">100k</span><span> &  </span>
</li>
</ol>
Copy after login

或甚至:

<ol class="dp-xml">
<li class="alt">shell> safe_MySQL<span>(和PHP搭配之最佳组合)d -O </span><span class="attribute">key_buffer</span><span>=</span><span class="attribute-value">512k</span><span> -O </span><span class="attribute">sort_buffer</span><span>=</span><span>16k \   </span>
</li>
<li>
<span>-O </span><span class="attribute">table_cache</span><span>=</span><span class="attribute-value">32</span><span> -O </span><span class="attribute">record_buffer</span><span>=</span><span class="attribute-value">8k</span><span> -O </span><span class="attribute">net_buffer</span><span>=</span><span class="attribute-value">1K</span><span> &  </span>
</li>
</ol>
Copy after login

如果有很多连接,“交换问题”可能发生,除非MySQL(和PHP搭配之最佳组合)d已经被配置每个连接使用很少的内存。当然如果你对所有连接有足够的内存,MySQL(和PHP搭配之最佳组合)d执行得更好。

注意,如果你改变MySQL(和PHP搭配之最佳组合)d的一个选项,它实际上只对MySQL服务器的那个例子保持。

为了明白一个参数变化的效果,这样做:

<ol class="dp-xml"><li class="alt">shell> MySQL<span>(和PHP搭配之最佳组合)d -O </span><span class="attribute">key_buffer</span><span>=</span><span>32m --help  </span>
</li></ol>
Copy after login

保证--help选项是最后一个;否则,命令行上在它之后列出的任何选项的效果将不在反映在输出中。


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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
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)

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

C++ program optimization: time complexity reduction techniques C++ program optimization: time complexity reduction techniques Jun 01, 2024 am 11:19 AM

Time complexity measures the execution time of an algorithm relative to the size of the input. Tips for reducing the time complexity of C++ programs include: choosing appropriate containers (such as vector, list) to optimize data storage and management. Utilize efficient algorithms such as quick sort to reduce computation time. Eliminate multiple operations to reduce double counting. Use conditional branches to avoid unnecessary calculations. Optimize linear search by using faster algorithms such as binary search.

The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

See all articles