我使用的是MySQL 5.1.66版.我看到long_query_time变量是动态的,但是当我尝试时
set GLOBAL long_query_time=1;
Run Code Online (Sandbox Code Playgroud)
经过上面的操作再次尝试了
mysql> show variables like 'long_query_time';
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
从mysql控制台它没有被改变,为什么?
为什么我不能在CentOS 6.4上的MySQL 5.6上使用slow_query_log?
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
...
## Logging
## *** THESE LOGS WORK JUST FINE ***
log_error = /var/log/mysql/error.log
general_log_file = /var/log/mysql/mysql.log
general_log = 1
## *** THESE LOGS BREAK MYSQL ***
#log_slow_queries = /var/log/mysql/slow.log
#long_query_time = 5
#log-queries-not-using-indexes
Run Code Online (Sandbox Code Playgroud)
这是/var/log/mysql目录:
$ ls -lh
total 100K
-rw-r----- 1 mysql root 47K Nov 22 06:02 error.log
-rw-rw---- 1 mysql root 42K Nov 22 06:05 mysql.log
-rw-rw---- 1 mysql mysql 0 Nov 22 06:01 slow.log
Run Code Online (Sandbox Code Playgroud)
如果我取消注释/etc/my.cnf我收到的log_slow_query行有以下错误:
$ /etc/init.d/mysql …Run Code Online (Sandbox Code Playgroud) 所以我对慢查询日志的理解是,它记录了我们在my.conf文件中设置的> = time(以秒为单位)的所有查询的信息.
现在让我们来看3个不同的SELECT查询3个案例(针对具有INNODB引擎的表):
QUERY I: Query_time:32.937667 Lock_time:0.000081 Rows_sent:343 Rows_examined: 12714043
QUERY II: Query_time:12.937667 Lock_time:0.000081 Rows_sent:43 Rows_examined: 714043
QUERY III: Query_time:42.937667 Lock_time:0.000081 Rows_sent:18 Rows_examined: 483
对我来说,QUERY I和QUERY II看起来像是一个糟糕的查询或糟糕的索引(或缺少索引)或碎片化的表数据等(我可能错过的任何其他东西?)用户可能会看到以改善查询执行时间的可能情况.
但是对于QUERY III,我无法理解,我的意思是数据库真正错误的是它需要42秒才能检查483行并发送回其中的18行(锁定时间可忽略不计).当我看到它间歇性地发生时,这变得更加混乱.
所以我真正想问的是:
可能有很多因素影响这种慢查询,所以如果你觉得你需要更多的信息来帮助我,那么请告诉我.
我遇到的问题是MySQL似乎在慢查询日志中记录的查询比指定的时间更快.我已经配置MySQL来记录以下内容:
Server version: 5.1.54-1ubuntu4-log
+---------------------+-------------------------------+
| Variable_name | Value |
+---------------------+-------------------------------+
| log_slow_queries | ON |
| long_query_time | 2.000000 |
| slow_query_log | ON |
| slow_query_log_file | /var/log/mysql/mysql-slow.log |
+---------------------+-------------------------------+
4 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
但是,在我的慢查询日志中,我可以看到它正在记录亚秒级查询:
# Time: 121116 17:09:00
# User@Host: user[user] @ ip-10-x-x-x.ec2.internal [x.x.x.x]
# Query_time: 0.007098 Lock_time: 0.000075 Rows_sent: 50 Rows_examined: 2693
Run Code Online (Sandbox Code Playgroud)
我使用'SET GLOBAL ...'动态设置了上面的变量,但在此之前,long_query_time设置为1.000000秒.
知道为什么MySQL可以记录比指定的更快的查询吗?
我正在尝试在mysql 5.7上启用慢速查询记录并收到此错误:
2016-04-27T14:55:51.934612Z 0 [错误]未知变量'log-slow-queries =/var/log/mysql-query.log'
2016-04-27T14:55:51.934639Z 0 [错误]中止
在我的/etc/my.cnf文件中,我定义了"log-slow-queries =/var/log/mysql-query.log",但我将假设在5.7中无效.启用查询记录的正确my.cnf设置是什么?谢谢,
这是查询统一医学语言系统(UMLS)以查找与标准化单词相关的单词.这个查询结果是165MS,但如果我正在运行同一个查询的VIEW,则需要70秒.我是mysql的新手.请帮我.
查询:
SELECT a.nwd as Normalized_Word,
b.str as String,
c.def as Defination,
d.sty as Semantic_type
FROM mrxnw_eng a, mrconso b, mrdef c, mrsty d
WHERE a.nwd = 'cold'
AND b.sab = 'Msh'
AND a.cui = b.cui
AND a.cui = c.cui
AND a.cui = d.cui
AND a.lui = b.lui
AND b.sui = a.sui
group by a.cui
Run Code Online (Sandbox Code Playgroud)
查看定义:
create view nString_Sementic as
SELECT a.nwd as Normalized_Word,
b.str as String,
c.def as Defination,
d.sty as Semantic_type
FROM mrxnw_eng a, mrconso b, mrdef c, …Run Code Online (Sandbox Code Playgroud) 我正在使用亚马逊的RDS数据库和一些非常大的表,昨天我开始面临服务器上100%的CPU利用率和一堆以前没有发生的慢速查询日志.
我试图检查正在运行的查询并从explain命令面对此结果
+----+-------------+-------------------------------+--------+----------------------------------------------------------------------------------------------+---------------------------------------+---------+-----------------------------------------------------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------------------------+--------+----------------------------------------------------------------------------------------------+---------------------------------------+---------+-----------------------------------------------------------------+------+----------------------------------------------+
| 1 | SIMPLE | businesses | const | PRIMARY | PRIMARY | 4 | const | 1 | Using index; Using temporary; Using filesort |
| 1 | SIMPLE | activities_businesses | ref | PRIMARY,index_activities_users_on_business_id,index_tweets_users_on_tweet_id_and_business_id | index_activities_users_on_business_id | 9 | const | 2252 | Using index condition; Using where |
| 1 | SIMPLE …Run Code Online (Sandbox Code Playgroud) mysql database-performance query-performance amazon-rds mysql-slow-query-log
我遇到一些困难,想出正确的语法来为我的慢查询日志文件提取特定的主机信息:
我正在使用以下内容:
sudo pt-query-digest mysql-slow.log --since "2017-05-07 22:00:00" --until "2017-05-08 22:00:00" --filter ‘$event->{host} !~ m/^ip-1-1-1-1/’ > slow.log
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我试图排除所有1.1.1.1的IP.我无法弄清楚出了什么问题.
在我的慢查询日志中,我看到的是慢查询
# Time: 121107 16:34:02 # User@Host: web_node[web_node] @ localhost [127.0.0.1] # Thread_id: 34436186 Schema: test_db Last_errno: 0 Killed: 0 # Query_time: 1.413751 Lock_time: 0.000222 Rows_sent: 203 Rows_examined: 203 Rows_affected: 0 Rows_read: 203 # Bytes_sent: 7553 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0 # InnoDB_trx_id: 9B04384 SET timestamp=1352334842; SELECT id, email FROM test_data WHERE id IN (13089576,3002681,3117763,1622233,2941590,12305279,1732672,2446772,3189510,13084725,4943929,5855071,6572137,2266261,3003496,2024860,3336832,13758671,6477694,1796684,13001771,4690025,1071744,1017876,5175795,795988,1619821,2481819,2941090,4770802,13438250,3254708,2323402,526303,13219855,3313573,3190479,1733761,3300577,2941758,6474118,1733379,11523598,4205064,6521805,2492903,1860388,3337093,5205317,1213970,5442738,12194039,1214203,12970536,3076611,3126152,3677156,5305021,2751587,4954875,875480,2105172,5309382,12981920,5204330,13729768,3254503,5030441,2680750,590661,1338572,7272410,1860386,2567550,5434143,1918035,5329411,1683235,3254119,5175784,1855380,3336834,2102567,4749746,37269,3207031,6464336,2227907,2713471,3937600,2940442,2233821,5619141,5204711,5988803,5050821,10109926,5226877,5050275,1874115,13677832,5338699,2423773,6432937,6443660,1990611,6090667,6527411,6568731,3254846,3414049,2011907,5180984,12178711,8558260,3130655,5864745,2059318,3480233,2104948,2387703,1939395,5356002,2681209,1184622,1184456,10390165,510854,7983305,795991,2622393,4490187,9436477,5356051,2423464,5205318,1600499,13623229,3255205,12200483,6477706,3445661,5226284,1176639,13760962,2101681,6022818,12909371,1732457,2377496,7260091,12191702,2492899,2630691,13047691,1684470,9382108,2233737,13117701,1796698,2535914,4941741,4565958,1100410,2321180,13080467,813342,4563877,4689365,2104756,1102802,2714488,3188947,1599770,1558291,5592740,5233428,5204830,1574452,3188956,13693326,2102349,3704111,1748303,790889,9323280,4741494,2387900,5338213,3583795,2283942,3189482,3002296,4490123,3585020,962926,3481423,1600920,1682364,4693123,6487778,2677582,2377195);
当我使用SQL_NO_CACHE通过探查器运行慢速查询时,它看起来如此
203 rows in set (0.03 sec) show profile for query 33; +----------------------+----------+ | Status | Duration | +----------------------+----------+ | starting | 0.000187 | …
mysql innodb query-optimization database-performance mysql-slow-query-log
嗨,我正在使用MySQL 5.5版,有人可以帮我清除/刷新mysql中的mysql.slow_log表中的数据吗?
mysql ×10
database ×2
my.cnf ×2
amazon-rds ×1
bash ×1
innodb ×1
percona ×1
performance ×1
sql ×1