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. editplus5激活码

    editplus5激活码 name: Vovan code: 3AG46-JJ48E-CEACC-8E6EW-ECUAW 转自:https://blog.csdn.net/webfront/artic ...

  2. MVC 枚举绑定 DropDownList

    /// <summary> /// 枚举转化下拉列表数据集 /// </summary> /// <param name="type">类型&l ...

  3. C++异常及捕获_01

    ZC: Win7x64 + qt-opensource-windows-x86-msvc2010_opengl-5.3.2.exe 1. class AA { public: void A() { & ...

  4. OpenGL入门程序二:绘制简单的圆

    学习 绘制一个圆: ; const float Pi = 3.1415926536f; const float R = 0.5f; //绘制一个圆 void DrawCircle() { //绘制一个 ...

  5. 终于用ADB连上平板了

    可以看到设备管理器里, ADB Interface 设备装不上驱动. 1,百度到的内容,没有一个靠谱的. 2,google到内容了, 却因为看的不仔细,浪费了好多时间...(android自己的文章都 ...

  6. Java注解 框架开发之Java注解的妙用

    原文出处: locality 注解的好处: 1.能够读懂别人写的代码,特别是框架相关的代码. 2.本来可能需要很多配置文件,需要很多逻辑才能实现的内容,就可以使用一个或者多个注解来替代,这样就使得编程 ...

  7. 『PyTorch』第十三弹_torch.nn.init参数初始化

    初始化参数的方法 nn.Module模块对于参数进行了内置的较为合理的初始化方式,当我们使用nn.Parameter时,初始化就很重要,而且我们也可以指定代替内置初始化的方式对nn.Module模块进 ...

  8. 『Scrapy』终端调用&选择器方法

    Scrapy终端 示例,输入如下命令后shell会进入Python(或IPython)交互式界面: scrapy shell "http://www.itcast.cn/channel/te ...

  9. UVA-10127 Ones (数论)

    题目大意:给一个数n,找出一个各位全是1的最小的十进制数,使得n能整除这个数.只输出最小位数. 题目分析:纯粹是数论,暴力. 代码如下: # include<iostream> # inc ...

  10. 基础最短路(模板 spfa)

    Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还 ...