The MySQL slow query log often shows a bunch of following entries in sequence.
SET timestamp=1268999330;
commit;
# User#Host: username[username] # localhost []
# Query_time: 4.172700 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
SET timestamp=1268999330;
commit;
# User#Host: username[username] # localhost []
# Query_time: 3.628924 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
SET timestamp=1268999330;
commit;
# User#Host: username[username] # localhost []
# Query_time: 3.116018 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
...
Usually 6-7 "commit" queries in sequence. Anyone what they are and what's the preceding query of each of them?
Thanks in advance.
the set timestamp command affects the value returned by now and the value that auto timestamp columns receive when their rows are modified.
this is necessary for replication and when playing back the log. query semantics that depend on the current time will always match exactly. (note sysdate disregards set timestamp unlike now)
the log will make sure the timestamp is recorded with set timestamp whenever there's a new connection, a mysql ping, or any statement executed.
Related
If the unit of time in MySQL's slow-query log is second (according to the SO answer), what does the following line from my MySQL's slow-query log mean?
# Query_time: 18446744073709.550781 Lock_time: 0.000062 Rows_sent: 1 Rows_examined: 2
This request should take more than 500 years? ..
I am having a very strange situation in which i have mysql version 5.5.46 working with engine innoDB.
I have enables slow_log and long_query_time is set on 3 seconds,
and although i have in the slow log queries that finished with in less than 0.5 second and more queries such as selects/updates and inserts that finish with in 0.000037 seconds.
# Query_time: 0.002699 Lock_time: 0.000037 Rows_sent: 0 Rows_examined: 1
I checked weather i have enabled the parameter log_queries_not_using_indexes but it is OFF.
I tried to disable slow-log set in to off then on.
I tried on setting the long_query_time to 10 seconds but it does not help the issue.
Restart is not an option currently on a production system.
I searched everywhere for solution, the only thing i can think on is to set the global variable: min_examined_row_limit to more than 1 since almost all of the queries that finish with in less than 1 second examine only 1 row, but i would not want that because it may hide problems later.
Some of the logs for example:
INSERT INTO xxx (X values);
# Time: 170521 9:47:46
# Query_time: 0.006520 Lock_time: 0.000041 Rows_sent: 0 Rows_examined: 1
SET timestamp=1495374466;
UPDATE 'schema_name'.'replication_heartbeat' SET ts='2017-05-21T09:47:46.000720', file='test-db44-bin.089771', position='10638144', relay_master_log_file=NULL, exec_master_log_pos=NULL WHERE server_id='44';
# Time: 170521 9:47:47
# Query_time: 0.014305 Lock_time: 0.000043 Rows_sent: 0 Rows_examined: 1
SET timestamp=1495374467;
UPDATE 'schema_name'.'replication_heartbeat' SET ts='2017-05-21T09:47:47.000700', file='test-db44-bin.089771', position='10760016', relay_master_log_file=NULL, exec_master_log_pos=NULL WHERE server_id='44';
Does anyone have any idea of how to remove all that junk from the slow log?
Thanks everyone,
Leon.
I have Mysql DB on AWS RDS instance, and I have a slow query log with log_queries_not_using_indexes = YES
And it is working but almost every 5 seconds, this is what I am seeing in log:
SELECT value FROM mysql.rds_heartbeat2;
# Time: 150804 21:00:25
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000154 Lock_time: 0.000058 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722025;
SELECT NAME, VALUE FROM mysql.rds_configuration;
# Time: 150804 21:00:30
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000233 Lock_time: 0.000113 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722030;
SELECT count(*) from information_schema.TABLES WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'rds_heartbeat2';
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000116 Lock_time: 0.000039 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722030;
SELECT value FROM mysql.rds_heartbeat2;
# Time: 150804 21:00:45
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000238 Lock_time: 0.000116 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722045;
SELECT count(*) from information_schema.TABLES WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'rds_heartbeat2';
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000112 Lock_time: 0.000036 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722045;
SELECT value FROM mysql.rds_heartbeat2;
# Time: 150804 21:01:00
What is this?
I have maybe one or two my queries which I need to optimize and rest of log file is this.
How is this related to my databases? Those queries are not mine. I believe this is something what AWS do but I don't know why and how it affects the performance.
Those database are part of the Mysql server. Although I suspect that rds_heartbeat2 and rds_configuration are specific to the AWS RDS version of mysql. You can read more about heartbeat.
From dev.mysql:
INFORMATION_SCHEMA is a database within each MySQL instance, the place that stores information about all the other databases that the MySQL server maintains. The INFORMATION_SCHEMA database contains several read-only tables. They are actually views, not base tables, so there are no files associated with them, and you cannot set triggers on them. Also, there is no database directory with that name.
You can run this command to see which databases have MyISAM Tables:
select distinct(table_schema) FROM information_schema.tables where engine = 'MyISAM';
From dev.mysql.
The mysql system database includes several grant tables that contain information about user accounts and the privileges held by them.
You can run this command to see a list of users and host:
select user, host from mysql.user;
I'm having some issues logging the slow queries in my MySQL 5.1 instance. It seems to be logging every query, not just the slow ones.
Here's a sample of the logging...
# User#Host: root[root] # localhost [127.0.0.1]
# Query_time: 0.000000 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 11
SET timestamp=1398191470;
SELECT count(distinct(user_id)) as user_id from user_sessions where role='bidder';
# User#Host: root[root] # localhost [127.0.0.1]
# Query_time: 0.000000 Lock_time: 0.000000 Rows_sent: 9 Rows_examined: 11
SET timestamp=1398191470;
SELECT user_name FROM user_sessions WHERE last_access_ts > '2014-04-22 14:30:59';
Here's the entries in my mysql.ini file....
long_query_time = 3
slow_query_log
log-queries-not-using-indexes
You have "log-queries-not-using-indexes" turned on. That causes the server to consider all queries that are not using indexes to be "slow".
To resolve your issue, either remove "log-queries-not-using-indexes" or add indexes on "role" and "last_access_ts" fields to user_sessions table.
I have a MySQL slow query log that shows the same query was run twice within a few minutes. There were no additions to the table and the key fields were not changed on any records during that time. Why would the number of rows examined be different?
# Time: 130615 11:35:59
# User#Host: root[root] # localhost [127.0.0.1]
# Query_time: 32.198606 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 68851
SET timestamp=1371314159;
SELECT * FROM `projectaddresses` WHERE `ID_PROJECT` = 77 ORDER BY `ID_PROJECTADDRESS` ASC LIMIT 25 OFFSET 0;
# Time: 130615 11:37:22
# User#Host: root[root] # localhost [127.0.0.1]
# Query_time: 30.030193 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 163319
SET timestamp=1371314242;
SELECT * FROM `projectaddresses` WHERE `ID_PROJECT` = 77 ORDER BY `ID_PROJECTADDRESS` ASC LIMIT 25 OFFSET 0;
This query normally returns within a second. ID_PROJECTADDRESS is the primary key and there is an index on ID_PROJECT with cardinality of 110.
The only thing I found on the MySQL forum suggested that index statistics were updated, but I don't think that makes sense here.
I assume that the fact that this query normally runs quickly and doesn't appear in the slow query log is related to the same issue. Any ideas as to what that issue may be would be appreciated.
If your primary key isn't unique, then MySQL is just reading rows until it has 25 matched rows, then it stops. There is no guarantee the rows will be read in the same order each time unless your ORDER BY is unique. Rows are read in the most convenient way, so sometimes it may need to read more rows to find 25 that match.