Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The enabling method of MySQL slow query log and the implementation of analysis on Linux

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Let's talk about how to enable the MySQL slow query log and implement the analysis on Linux. The secret of the text is close to the topic. So, no gossip, let's go straight to the following, I believe you will benefit from reading the enabling method of MySQL slow query log and implementing the analysis of this article on Linux.

Connect to the Plesk CVM through SSH.

Enable the MySQL slow query log my.cnf in the MySQL configuration file:

2.1 . My.cnf opens the file in any text editor. In this example, we use the "vi" editor:

2.2 . Add the following records under the [mysqld] section:

Slow_query_log = 1

Log-slow-queries = / var/log/mysql-slow.log

Long_query_time = 2

Note: In MySQL 5.7, the variable log-slow-queries is deprecated. Use slow_query_log_file instead.

2.3 . Save the changes and close the file.

The time taken by the long_query_time-SQL query to execute in a few seconds. If the query time exceeds the specified value, the query is recorded in the slow query log file.

On CentOS / RHEL-based distributions:

# vi / etc/my.cnf

On Debian / Ubuntu distributions:

# vi / etc/mysql/my.cnf

Create a slow query log file / var/log/mysql-slow.log (http://www.2fgk.com)) and set the correct ownership for it:

# touch / var/log/mysql-slow.log

# chown mysql:mysql / var/log/mysql-slow.log

Restart MySQL. This command depends on the operating system and the installed version of MySQL:

CentOS / RHEL-based distributions:

# service mysqld restart

For Debian / Ubuntu-based distributions:

# service mysql restart

If MariaDB is installed:

# service mariadb restart

Start monitoring slow query log files. Use the command mysqldumpslow to analyze it and print a summary of the slow query log file.

For example, to print all recorded slow queries, run the following command:

# mysqldumpslow-a / var/log/mysql-slow.log

A complete list of mysqldumpslow options can be found here.

Is there anything you don't understand about the above enabling method of MySQL slow query log and the implementation of analyzing the relevant content on Linux? Or if you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report