When I execute \s in MySQL console, I get a bunch of information. Also the information I don't care about. I just want to get slow queries and Queries per second avg.
I found solution for slow_queries because it is present in the status table of MySQL. However, Queries per second average isn't available in the MySQL status table.
Is there any way to get only Queries per second average? I can use grep to scrap the information I need in the SSH Console but I don't want to expose MySQL password in logs. This process is automated and not manual. So, the process has to be non-interactive.
I tried to find information in the performance_schema but it looks like I am missing something. Is this value calculated while execution of \s command?
Related
MySql 5.5 has a few logging option, among which the "Binary Logfile" with Binlog options which I do not want to use and the "query log file" which I want to use.
However, 1 program using 1 table in that database is filling this logfile with 50+Mb per day, so I would like that table to be excluded from this log.
Is that possible, or is the only way to install another MySql version and then to move this 1 table?
Thanks,
Alex
There are options for filtering the binlog by table, but not the query logs.
There are no options for filtering the general query log. It is either enabled for all queries, or else it's disabled.
There are options for filtering the slow query log, but not by table. For example, to log only queries that take longer than N seconds, or queries that don't use an index. Percona Server adds some options to filter the slow query log based on sampling.
You can use a session variable to disable either slow query or general query logging for queries run in a given session. This is a dynamic setting, so you can change it at will. But you would need to change your client code to do this every time you query that specific table.
Another option is to implement log rotation for the slow query log, so it never grows too large. See https://www.percona.com/blog/2013/04/18/rotating-mysql-slow-logs-safely/
As per my research I thought of using the mysqldumpslow utility to parse the log and extract the results, but not able to figure out how to use it. I want to get the count of number of queries logged in the slow query log for an interval of 10 minutes, so that the values can be compared for analysis.
Thanks
You could use logrotate to create a new slow.log every 10 minutes and analyze them one after another. Implying you are using Linux. Be aware that your example shows that your mysql instance is configured to "log-queries-not-using-indexes" hence you will also get those SELECT's that dont use an index in your log file too.
Update :
Since i still dont know what OS you are using, a more general aproach to your problem would be redirecting the slow log into mysql itself following the mysql docs and get all records from the slow log table like :
SELECT COUNT(*) FROM slow_log;
Which gives you the total amount of Querys logged. Follwed by a :
TRUNCATE TABLE slow_log;
Having a script in place doing this every 10 minutes would output the desired information.
I have a special security need with mysql. I need to forcibly restrict the number of rows a query returns, issuing an error if the returned rows will be over, say a million rows. Here is the setup -
Need - The data has 100s of millions of rows, and we don't want the client to run down the server or do a complete extraction (They would never need all the lines, just aggregations) The idea is, if they need it, they run into an error or the barrier, and come to us with the reason explaining why they need to pull so many rows with a query.
System - Clients can use any query tool, so we have no control over what query is generated. Thus, we cannot use Limit x which seems to be the solution suggested everywhere.
I have tried searching for a solution, and for now it seems that the only way to do it is at the application level (which we do not own).
Is there any way to achieve this?
Setting
1- We need to have SSL enabled.
2- MySQL 5.5
Thanks!
J
It seems like you might be able to get close with MySQL Proxy.
https://launchpad.net/mysql-proxy
See this page for manipulating results. Not sure if it does a buffered or unbuffered read, or if you can cancel the reading of results or not...
http://dev.mysql.com/doc/refman/5.1/en/mysql-proxy-scripting-read-query-result.html
It's open source, so you might be able to hire someone to tweak it if needed as well.
There may be other ways to restrict the overloading of your database server. Take a look at this link for more info:
MySQL - can I limit the maximum time allowed for a query to run?
I have a very slow query that is built by the ORM and I'm curios how could I find out the exact query being executed.
I cannot monitor it from the mysql-slow.log because it never finishes the execution (as in I don't have eternity to wait for it, more than an hour in an still waiting).
Also I cannot get the query from the ORM, just after execution. And the only way I think of getting it is from the process list.
show processlist \G
But my problem is that most of the query is trimmed of, even before the from keyword.
This question has been asked before but with no answer https://stackoverflow.com/questions/3741356/find-queries-from-process-id-mysql-5-1-x
Any suggestions?
If your query is formatted in multiple lines, some MySQL clients will only display the first line. To see full output run SHOW FULL PROCESSLIST; query in MySQL console.
How do you find out how many queries have been executed since the MySQL server has started?
If you want to do it in a query, instead of by running an external program:
SHOW GLOBAL STATUS LIKE 'Questions';
mysqladmin proc stat
This should give you a Questions count (among other information), which is the number of queries asked of the server.
One handy part of the info returned is slow queries count. Hopefully that is 0. :)
In MySQL 5.1.31 or later, you can do show status and check out the row with the name "Queries"
http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Queries
If you don't have 5.1, use the "Questions" row. In 5.1, it won't include queries inside saved procedures.
http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Questions
Just
mysqladmin status -p
should give you the useful information and specific information.