MySQL Slow Log issues - long_query_time does not go into effect - mysql

I have followed a few tutorials in tracking down slow queries through the slow query log.
I have tried changing long_query_time to the value of 1 for testing purposes, but whatever I do, a query only makes it into the log when the default time of 10 is reached.
I tried:
set ##GLOBAL.long_query_time = 1;
set global long_query_time = 1;
When using either of these commands:
show variables like '%long%';
show global variables like '%long%';
I get the result that the variable was changed.
I have the exact same query running, just adding more LEFT JOIN entries to make it run longer. Whenever the query runs 10 seconds or longer, it is logged, but it does NOT show up in the log when it runs less than that, even though all my variables appear to say they are changed.
I am logged into MySQL as root as I make these changes.
I restarted Apache and MySQL, still no dice.
My version information is:
Server version: 5.1.63-log SUSE MySQL RPM
When I query both the session and the global variables (I tried both), I get this:
mysql> show variables like '%long%';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| long_query_time | 1.000000 |
| max_long_data_size | 1048576 |
+--------------------+----------+
2 rows in set (0.00 sec)
mysql> show global variables like '%long%';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| long_query_time | 1.000000 |
| max_long_data_size | 1048576 |
+--------------------+----------+
2 rows in set (0.00 sec)
The general logging feature is obviously on, and it is redirected to TABLE or I wouldn't get an entry in the log at all.
The setting log_queries_not_using_indexes if turned on starts logging EVERY query even if it does not take 1 second to execute.
What am I missing?
Thanks!

The configuration below turns MySQL to log queries which execution time is more than half second:
slow_query_log = 1
long_query_time = 0.5
log-slow-queries = /var/log/mysql/log-slow-queries.log
log_queries_not_using_indexes = 0

Related

phpmyadmin copy variables [duplicate]

Can not find a command that displays the current configuration of mysql from within the database.
I know I could look at /etc/mysql/my.cnf but that is not what I need.
What you are looking for is this:
SHOW VARIABLES;
You can modify it further like any query:
SHOW VARIABLES LIKE '%max%';
Use SHOW VARIABLES:
show variables like 'version';
As an alternative you can also query the information_schema database and retrieve the data from the global_variables (and global_status of course too). This approach provides the same information, but gives you the opportunity to do more with the results, as it is a plain old query.
For example you can convert units to become more readable. The following query provides the current global setting for the innodb_log_buffer_size in bytes and megabytes:
SELECT
variable_name,
variable_value AS innodb_log_buffer_size_bytes,
ROUND(variable_value / (1024*1024)) AS innodb_log_buffer_size_mb
FROM information_schema.global_variables
WHERE variable_name LIKE 'innodb_log_buffer_size';
As a result you get:
+------------------------+------------------------------+---------------------------+
| variable_name | innodb_log_buffer_size_bytes | innodb_log_buffer_size_mb |
+------------------------+------------------------------+---------------------------+
| INNODB_LOG_BUFFER_SIZE | 268435456 | 256 |
+------------------------+------------------------------+---------------------------+
1 row in set (0,00 sec)

How to calculate amount of work performed by the page cleaner thread each second?

I try to tune InnoDB Buffer Pool Flushing parameters.
In MySQL 5.7 manual
innodb_lru_scan_depth * innodb_buffer_pool_instances = amount of work performed by the page cleaner thread each second
My question is : How can I calculate the amount of work performed by the page cleaner thread each second?
Run the SQL command:
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_pages_flushed'
Once every second. Compare the value to the previous second.
The difference of that value from one second to the next is the number of dirty pages the page cleaner requested to flush to disk.
Example:
mysql> SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_pages_flushed';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| Innodb_buffer_pool_pages_flushed | 496786650 |
+----------------------------------+-----------+
...wait a moment...
mysql> SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_pages_flushed';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| Innodb_buffer_pool_pages_flushed | 496787206 |
+----------------------------------+-----------+
So in the moment I waited, the page cleaner flushed 556 pages.
The upper limit of this work is a complex calculation, involving several InnoDB configuration options. Read my answer to How to solve mysql warning: "InnoDB: page_cleaner: 1000ms intended loop took XXX ms. The settings might not be optimal "? for a description of how it works.

How to increase MySQL connections(max_connections)?

Every socket of MySQL Database will have defaults connections as 100 but I am looking for any way to increase the number of possible connections > 100 to a socket connection of MySQL Database.
If you need to increase MySQL Connections without MySQL restart do like below
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> SET GLOBAL max_connections = 150;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 150 |
+-----------------+-------+
1 row in set (0.00 sec)
These settings will change at MySQL Restart.
For permanent changes add below line in my.cnf and restart MySQL
max_connections = 150
From Increase MySQL connection limit:-
MySQL’s default configuration sets the maximum simultaneous connections to 100. If you need to increase it, you can do it fairly easily:
For MySQL 3.x:
# vi /etc/my.cnf
set-variable = max_connections = 250
For MySQL 4.x and 5.x:
# vi /etc/my.cnf
max_connections = 250
Restart MySQL once you’ve made the changes and verify with:
echo "show variables like 'max_connections';" | mysql
EDIT:-(From comments)
The maximum concurrent connection can be maximum range: 4,294,967,295. Check MYSQL docs
I had the same issue and I resolved it with MySQL workbench, as shown in the attached screenshot:
in the navigator (on the left side), under the section "management", click on "Status and System variables",
then choose "system variables" (tab at the top),
then search for "connection" in the search field,
and 5. you will see two fields that need to be adjusted to fit your needs (max_connections and mysqlx_max_connections).
Hope that helps!
The system does not allow me to upload pictures, instead please click on this link and you can see my screenshot...

Mysql event log (monitoring)

I have events every night in my MYSQL, and I don't really sure what is going on because it's still running in the morning even if I set it earlier than the other event.
The question is,
how can I check the history or the log of the ran events,
which one is locked at night or which one is ran on not ran?
Thank you
this line will help you:
SELECT * FROM INFORMATION_SCHEMA.events;
You can enable slow query log in MySQL server so as to log in the slow queries in a file or MySQL table. Follow theses steps:
Check if slow query log is enabled for your MySQL server or not. Execute these query on the MySQL server.
mysql> show global variables like "%slow_query_log%";
+---------------------+----------------------------------+
| Variable_name | Value |
+---------------------+----------------------------------+
| slow_query_log | OFF |
| slow_query_log_file | /var/lib/mysql/siddhant-slow.log |
+---------------------+----------------------------------+
2 rows in set (0.00 sec)
If slow query log is not enabled, enable it like this.(or you can enable it in my.cnf or my.ini MySQL configuration file)
mysql> set global slow_query_log="ON";
Query OK, 0 rows affected (0.01 sec)
Also check the long query running time i.e. the time taken by the query to be considered as a slow query. The queries taking more time than this value would be logged in the slow query log.
mysql> show global variables like "%long_query%";
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)
Set this value to your requirement as follows.(here i am setting it to two seconds)
mysql> set global long_query_time=2;
Query OK, 0 rows affected (0.00 sec)
Now the slow queries will be logged in the slow query log file path as earlier returned by the query. I requirements are such that I need to monitor MySQL in real-time, you can have a look at this commercial GUI MySQL- Monitoring Tool. It analyzes the slow query log in real time.

mysql command for showing current configuration variables

Can not find a command that displays the current configuration of mysql from within the database.
I know I could look at /etc/mysql/my.cnf but that is not what I need.
What you are looking for is this:
SHOW VARIABLES;
You can modify it further like any query:
SHOW VARIABLES LIKE '%max%';
Use SHOW VARIABLES:
show variables like 'version';
As an alternative you can also query the information_schema database and retrieve the data from the global_variables (and global_status of course too). This approach provides the same information, but gives you the opportunity to do more with the results, as it is a plain old query.
For example you can convert units to become more readable. The following query provides the current global setting for the innodb_log_buffer_size in bytes and megabytes:
SELECT
variable_name,
variable_value AS innodb_log_buffer_size_bytes,
ROUND(variable_value / (1024*1024)) AS innodb_log_buffer_size_mb
FROM information_schema.global_variables
WHERE variable_name LIKE 'innodb_log_buffer_size';
As a result you get:
+------------------------+------------------------------+---------------------------+
| variable_name | innodb_log_buffer_size_bytes | innodb_log_buffer_size_mb |
+------------------------+------------------------------+---------------------------+
| INNODB_LOG_BUFFER_SIZE | 268435456 | 256 |
+------------------------+------------------------------+---------------------------+
1 row in set (0,00 sec)