MySQL “SET NAMES” near the top of the slow query log

后端 未结 1 1436
误落风尘
误落风尘 2021-02-10 22:30

On a recently launched site, I noticed that, well over the actual heavy queries on the site, the most costly request, out of several million queries, is actually SET NAMES, whic

相关标签:
1条回答
  • 2021-02-10 22:43

    If all queries are slow, SET NAMES can have a very low priority on the server, and therefore wait until the load dies down. If you have a lot of other queries that take a long time executing, you might want to try to optimize those first.

    Another solution to this "problem", could be adding this to your my.cnf on the server:

    [mysqld]
    init-connect = 'SET NAMES utf8'
    

    This makes sure the character set is set to UTF-8 when a client connects, so the client does not have to wait for the result of this "query". You probably want to disable the SET NAMES query in your software.

    Mainly, I wouldn't worry too much unless you really have A LOT of SET NAMES that takes this long.

    0 讨论(0)
提交回复
热议问题