Caution: Don’t overwrite your entire my.cnf at once when tuning MySQL. One
or two changes per restart, benchmark, then continue. Take backups first and be careful!

It took me some time to decide the title for this article. MariaDB has been fast replacing MySQL as a growing number of Linux distributions now default to MariaDB over MySQL. In addition, DBA’s often manually replace MySQL with MariaDB.

MariaDB is an enhanced drop-in replacement for MySQL. Therein lies my largely self-made conundrum, MySQL or MariaDB? Last month I posted a poll on
the Linux Google+ community: Which
would you suggest… MySQL or MariaDB? And why?

The MySQL tuning advice below applies to both MySQL and MariaDB (and Percona) . After tuning MySQL over the years I can safely say that the following pitfall is one of the most common…

Tuning MySQL (my.cnf) – Avoid arbitrarily increasing per connection buffers

The my.cnf config file is well-known but also often grossly misconfigured. I’m not sure where or when it all started but it has become the norm to keep increasing the size and value of almost every setting in my.cnf without much reasoning behind
those increases. Lets look at some important my.cnf parameters, where doing this, will not only hurt performance but also waste large chunks your server’s memory and as a result reduce MySQL’s overall capacity and throughput.

Related:  PHP
performance: oPcache Control Panels

Not all buffers in my.cnf are global settings

Buffers such as join_buffer_size, sort_buffer_size, read_buffer_size and read_rnd_buffer_size are
allocated per connection. Therefore a setting of read_buffer_size=1M and max_connections=150 is asking
MySQL to allocate – from startup – 1MB per connection x 150 connections. For more than a decade the default remains at 128K. Increasing the default is not only a waste of server memory, but often does not help performance. In nearly all cases its best to use
the defaults by removing or commenting out these four buffer config lines. For a more gradual approach, reduce them in half to free up wasted RAM, keep reducing them towards default values over time. I’ve actually seen improved throughput by reducing these buffers.
But there’s really no performance gains from increasing these buffers except in cases of very high traffic and/or other special circumstances. Avoid arbitrarily increasing these!

Tuning MySQL join_buffer_size

The join_buffer_size is allocated for each full join between two tables. From MySQL’s
documentation
 the join_buffer_size is described as: “The minimum size of the buffer that is used for plain index scans, range index scans, and joins that do not use indexes and thus perform full table scans.” It goes on to say: “Memory allocation time
can cause substantial performance drops if the global size is larger than needed by most queries that use it.” The join buffer is allocated to cache table rows when the join can’t use an index. If your database(s) suffer from many joins performed without indexes
it cannot be solved by just increasing join_buffer_size. The problem is “joins performed without indexes” and thus the solution for faster joins is to add indexes.

Related:  Download
LEMP for Raspberry Pi: Nginx + MariaDB (MySQL) + PHP

Tuning MySQL sort_buffer_size

Unless you have data to show otherwise, you should avoid arbitrarily increasing the sort_buffer_size as well. Memory here is also assigned per connection! MySQL’s
documentation warns: “On Linux, there are thresholds of 256KB and 2MB where larger values may significantly slow down memory allocation, so you should consider staying below one of those values.” Don’t increase above 2M since there is a performance penalty
going higher which sometimes can eliminate any benefits.

Rule of thumb when tuning MySQL, if you can’t provide a valid reason for increasing any of these buffers, keep them set to defaults (comment-out of config). These
four often attract large increases from admins when tuning MySQL. If we think about the meaning of the word “buffer” we can easily see why these buffers are not the my.cnf settings which require such heavy attention.

Hopefully you’ve found the MySQL tuning info useful. Also see another pitfall: MySQL
Query Cache Size and Performance
. (Not mentioned in that article, but if you are using mostly InnoDB tables, then you may be better off just disabling query_cache completely). If using MariaDB you should also use Aria table types over MyISAM and Innodb
in some cases. Aria tables perform really well!

MySQL配置优化需要避免的误区的更多相关文章

  1. mysql配置优化

    [笔记]MySQL 配置优化   安装MySQL后,配置文件my.cnf在 /MySQL安装目录/share/mysql目录中,该目录中还包含多个配置文件可供参考,有my-large.cnf ,my- ...

  2. 浅谈mysql配置优化和sql语句优化【转】

    做优化,我在这里引用淘宝系统分析师蒋江伟的一句话:只有勇于承担,才能让人有勇气,有承担自己的错误的勇气.有承担错误的勇气,就有去做事得勇气.无论做什么事,只要是对的,就要去做,勇敢去做.出了错误,承担 ...

  3. mysql配置优化的参数

    1.MySQL数据库高效优化解析  Mysql优化是一项非常重要的工作,而且是一项长期的工作,曾经有一个为位DBA前辈说过:mysql的优化,三分配置的优化,七分sql语句的优化. Mysql的优化: ...

  4. 4G内存服务器的MySQL配置优化

    公司网站访问量越来越大(日均超10万PV),MySQL自然成为瓶颈,关于 MySQL 的优化,最基本的是 MySQL 系统参数的优化. MySQL对于web架构性能的影响最大,也是关键的核心部分.My ...

  5. MySql配置优化总结

    当我们被人雇来监测MySQL性能时,人们希望我们能够检视一下MySQL配置然后给出一些提高建议.许多人在事后都非常惊讶,因为我们建议他们仅仅改动几个设置,即使是这里有好几百个配置项.这篇文章的目的在于 ...

  6. Mysql配置优化,库表设计

    Mysql 服务器参数类型: 基于参数的作用域: 全局参数:set global autocommit = ON/OFF; 会话参数(会话参数不单独设置则会采用全局参数):set session au ...

  7. mysql配置优化浅谈(一)

    MySQL对于web架构性能的影响最大,也是关键的核心部分.MySQL的设置是否合理优化,直接影响到web的速度和承载量!同时,MySQL也是优化难度最大的一个部分,不但需要理解一些MySQL专业知识 ...

  8. MySQL 配置优化

    1.   连接请求的变量: A.max_connections 如果服务器的并发连接请求量比较大,建议调高此值,以增加并行连接数量, 当然这建立在机器能支撑的情况下,因为如果连接数越多,介于MySQL ...

  9. 256MB小内存MySQL配置优化

    [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mys ...

随机推荐

  1. Springboot统一参数验证方式

    Springboot统一验证方式 在提供http api 接口形式的服务中,通过都会传递参数为一个对象.我们需要对这个对象的各个字段进行校验.来判断是否为合法值. 传统的方式为自己获取每个字段的值,自 ...

  2. BZOJ 1006: [HNOI2008]神奇的国度(弦图染色)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1006 题意: 思路: 这个就是弦图染色问题,弦图啥的反正我也不懂,具体看论文https://wenk ...

  3. UOJ #56. 【WC2014】非确定机

    题意大意:给出一个输出文件,求输入. 1.满足所求的输入文件是一张图,n个点,m条边,所用算法是k(k在给出的输出文件中给出了) 2.算法是图论算法?!k基本上→两位数组成,若十位数相同,说明基本算法 ...

  4. 基于Java的三种对象持久化方式

    1:序列化技术: 序列化的过程就是将对象写入字节流和从字节流中读取对象.将对象状态转换成字节流之后,可以用java.io包中的各种字节流类将其保存到文件中,可以通过管道或线程读取,或通过网络连接将对象 ...

  5. python 字节数组和十六进制字符串互转

    . 字节数组 --> 十六进制字符串 >>> a = 'ab' >>> a.encode('hex') ' . 十六进制字符串 --> 字节数组 > ...

  6. python input选择

    例1 import sys #声明字符串数组并初始化 newspaper=['1.北京晚报','2.作家文摘','3.参考消息', \ '4.证券报','5.不需要'] #字符串数组的输出 ): pr ...

  7. shell 关系运算符

    关系运算符 关系运算符只支持数字,不支持字符串,除非字符串的值是数字. 下表列出了常用的关系运算符,假定变量 a 为 10,变量 b 为 20: 运算符 说明 举例 -eq 检测两个数是否相等,相等返 ...

  8. c++ 判断给定区间是否是一个heap. O(N) (is_heap)

    #include <iostream> // cout #include <algorithm> // is_heap, make_heap, pop_heap #includ ...

  9. C89_一些函数

    C89 string.h 中的函数: 复制函数 memcpy memmove strcpy strncpy 串接函数 strcat strncat 比较函数 memcmp strcmp strcoll ...

  10. HDU 4489 The King's Ups and Downs

    HDU 4489 The King's Ups and Downs 思路: 状态:dp[i]表示i个数的方案数. 转移方程:dp[n]=∑dp[j-1]/2*dp[n-j]/2*C(n-1,j-1). ...