Linux Turn on slow query

Source: Internet
Author: User

Linux View MySQL installation path

First, view the file installation path


Since there is more than one place to install the software, all the paths (addresses) that are first said to view the file installation.

Take MySQL for example here. For example, I installed MySQL, but do not know where the files are installed, in which folders, you can use the following command to view all the file path
In Terminal input:

Whereis MySQL

Enter, if you installed MySQL, will show the file installation address, such as my display (the installation address may be different)

    1. [[email protected] ~]# Whereis MySQL

    2. MySQL:/usr/bin/mysql/usr/lib/mysql/usr/share/mysql/usr/share/man/man1/mysql.1.gz

Copy Code

Second, the path of the query running file (folder address)

If you just query the file's running file address, you can use the following command (or MySQL, for example):

which MySQL

Terminal display:

[[email protected] ~]# which MySQL
/usr/bin/mysql

Method One: Modify the MySQL my.cnf file

Linux:

In MySQL profile/etc/my.cnf, under [mysqld] option, add:

Vi/etc/my.cnf

Log-slow-queries=/usr/local/mysql/slowquery.log (Specify the log file location, can be empty, the system will give a default file Host_name-slow.log)
Long_query_time=1 (record over time, default is 10s)
Log-queries-not-using-indexes (log down without using the indexed query, depending on the situation to decide whether to open)
Log-long-format (if set, all queries that do not use the index will also be logged)

Windows:

In My.ini [mysqld], add the following statement:
Log-slow-queries = D:\www\mysql\log\mysqlslowquery.log
Long_query_time = 1 (other parameters as above)

Restart MySQL after saving to load the configuration

Attention
Llog-slow-queries=/usr/local/mysql/slowquery.log for slow query log storage location, generally this directory to have MySQL running account of the writable permissions, generally set this directory as MySQL data storage directory;
Long_query_time=1 1 indicates that the query is more than two seconds before logging;

Method Two: Command mode

Cd/usr/local/mysql/bin

Mysql-u root-p

Enter password

Mysql> Show variables like "%long%"; Check the default is slow query time 10 seconds

+ ————— –+ ——— –+

| variable_name | Value |

+ ————— –+ ——— –+

| Long_query_time | 10.000000 |

+ ————— –+ ——— –+

1 row in Set (0.00 sec)

mysql> set global long_query_time=2; Set to 2 seconds, plus global, the next time you enter MySQL is already in effect

Query OK, 0 rows Affected (0.00 sec)

Mysql> Show variables like "%slow%"; Check to see if the slow query is turned on

+ ——————— + ——————————— +

| variable_name | Value |

+ ——————— + ——————————— +

| log_slow_queries | OFF |

| Slow_launch_time | 2 |

| Slow_query_log | OFF |

| Slow_query_log_file | /usr/local/mysql/mysql-slow.log |

+ ——————— + ——————————— +

4 rows in Set (0.00 sec)

Mysql> set slow_query_log= ' on '; Add global, or you'll get an error.

ERROR 1229 (HY000): Variable ' Slow_query_log ' is a GLOBAL Variable and should BES set with set GLOBAL

mysql> set global slow_query_log= ' on '; Enable slow Query

Query OK, 0 rows affected (0.28 sec)

Mysql> Show variables like "%slow%"; See if it's turned on

+ ——————— + ——————————— +

| variable_name | Value |

+ ——————— + ——————————— +

| log_slow_queries | On |

| Slow_launch_time | 2 |

| Slow_query_log | On |

| Slow_query_log_file | /usr/local/mysql/mysql-slow.log |

+ ——————— + ——————————— +

4 rows in Set (0.00 sec)


This article is from the "lake and Laughter" blog, please make sure to keep this source http://hashlinux.blog.51cto.com/9647696/1793420

Linux Turn on slow query

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.