Count of all queries since MySQL server has started - mysql

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.

Related

How to get only 'Queries per second avg' in MySQL console?

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?

Can't Access Some Tables in MYSQL

I need a help that some of mysql tables are not accessable ( looks like deadlock) as my website is down and I can't open these tables through Navicat nor phpMyAdmin , I tried to kill the query by knowing the thread ID using:
SHOW FULL PROCESSLIST
but I didn't find any rows related to the issue.
Noting that the issue caused after I tried to run some heavy query to 2 tables which contain > 10 millions of row, and I cancelled the query after it took more than 3 hours.
I don't have access to reboot server, and I am using godaddy hosting, and they doesn't have online chatting support to my country!
Can I do anything to fix it by myside without rebooting!
please advice.
Even though it is 2 million rows the query should not take 3 hours, which means the SQL itself needs serious attention. As you said 'looks like deadlock' you can examine by SHOW ENGINE INNODB STATUS
If we get more tables in locked state then we may able to resolve these situations by setting the value of the innodb_lock_wait_timeout system variable.
For reference:
https://dev.mysql.com/doc/refman/5.7/en/glossary.html#glos_deadlock
https://www.percona.com/blog/2012/09/19/logging-deadlocks-errors/
In Unix-like OS you can use "system" or "\!" prefix to execute any command of shell inside mysql interpreter. See this.
Of course you must have admin privileges to run any commands in shell.
With this you can use some mysql admin command to get de PID and analise your problem by OS.

Error code: 2013: Lost connection to Mysql server during the query.. How can improve this query

I am getting the error stated in my post title. I have two tables. The first one, large is over than 4000,000 records and the second, small one is arounf 7000 records. I want to search for the value in the samll table and if found, I want to extract the whole record from the large table. The command never executed and always lose the connection with the database. I tried to limit the out put to 50 records only, the same thing happens. Please help me. If I need something like indexing (I read this might solve such performance problems, please clarify to me how. I'm not a DBA).
select * from db.large, db.small
where large.value=small.value;
*EDIT: * I use MySQL workbench 5.2.41 CE.
At one point on a previous project, I could actually crash the MySQL server reproducibly with a pretty simple query. In the code that called the database, I saw the same error message. Can you verify that the MySQL server's process ID is the same before and after the query? Chances are that your OS restarts the MySQL server immediately after the crash, and the MySQL command line client automatically reconnects (though it emits a notice when it does).

Analyzing query statistics in PhpMyAdmin

I'm trying to analyze my MySql database and server and when looking in phpmyadmin Status->Query statistics I can see that these three queries are the most used:
set option 31.91%
change db 15.71%
show variables 15.83%
I'm quite a newbie in MySql and my question is now: Why are these queries running so often? SELECT, INSERT, UPDATE and DELETE are not at all that frequently running on the server. I just wanted to see if this is normal behavior?
Thanks for your help!
It probably depends on the amount that you use phpMyAdmin vs running actual queries. My guess is that set option, change db, and show variables are used pretty often by phpMyAdmin.

How can I log MySQL queries?

Is it possible to log all queries that are executed? I am looking at a database that is accessed by many different apps. One of them is modifying a table's value in a way it should not. I am trying figure out which app is the culprit. It would help me out a lot if I can capture all the queries that are executed on that table and at what time.
Many thanks in advance for your help.
Either use the --log[=file_name] command line switch on mysqld or edit/create a my.cnf containing:
[mysqld]
log=/tmp/mysql.log
Explained fully in this article.
As far as I am aware, there are currently no auditing capabilities built in to MySQL. Log queries from within the applications that generate them, or sniff connections to the server.
in your .ini configuration add this line
log=allqueries.log
you will need to restart mysql
A possible solution to your problem is to utilize an update trigger on the table in question. The trigger will be fired on any update to the table, and it possible to write the trigger such that when it meets certain criteria (the value in question is changed), an action is performed (perhaps writing to a temporary table, the SQL statement that makes the change). For more information, I suggest looking at Trigger Syntax.
Take a look here: http://dev.mysql.com/doc/refman/5.1/en/server-logs.html
You're looking for general query log: http://dev.mysql.com/doc/refman/5.1/en/query-log.html
You can use the general log in MySQL to achieve this. I only recommend you do that on a test/development database without many concurrent users, because the amount of output generated is huge. I'm not sure if it logs the timestamp, though.
If it doesn't, on a unix/linux setup, I'd say write a simple script that read lines from the stdin and print the lines with the current timestamp when they were read, and pipe tail -f on the log file to it, so you can add your own timestamps.