Quick question:
I have created come commands that will warm-up my DB.
The thing is that those selects are large.
When I do such a select I get all the "jiba-jaba" into my terminal window.
How can you make mysql do the select 'quietly' ? without taking ages to print all the crap into my terminal ?
Mysql – thesql not to print selects output to terminal
MySQLshellterminal
Related Solutions
Please look carefully at the processlist and the 'show engine innodb status'. What do you see ???
Process IDs 1,2,4,5,6,13 are all trying to run COMMIT.
Who is holding up everything ??? Process ID 40 is running a query against large_table.
Process ID 40 has been running for 33 seconds. Process IDs 1,2,4,5,6,13 having been running less than 33 seconds. Process ID 40 is processing something. What's the hold up ???
First of all, the query is pounding on large_table's clustered index via MVCC.
Within Process IDs 1,2,4,5,6,13 are rows that have MVCC Data protecting its transaction isolation. Process ID 40 has a query that is marching through rows of data. If there is an index on the field hotspot_id, that key + the key to the actual row from the clustered index must perform an internal lock. (Note: By design, all non-unique indexes in InnoDB carry both your key (the column you meant to index) + a clustered index key). This unique scenario is essentially Unstoppable Force meets Immovable Object.
In essence, the COMMITs must wait until it is safe to apply changes against large_table. Your situation is not unique, not a one-off, not a rare phenomenon.
I actually answered three questions like this in the DBA StackExchange. The questions were submitted by the same person related to the same one problem. My answers were not the solution but helped the question submitter come to his own conclusion on how to handle his situation.
- Will these two queries result in a deadlock if executed in sequence?
- Trouble deciphering a deadlock in an innodb status log
- Reasons for occasionally slow queries?
In addition to those answers, I answered another person's question about deadlocks in InnoDB with regard to SELECTs.
I hope my past posts on this subject help clarify what was happening to you.
UPDATE 2011-08-25 08:10 EDT
Here is the query from Process ID 40
SELECT * FROM `large_table`
WHERE (`large_table`.`hotspot_id` = 3000064)
ORDER BY discovered_at LIMIT 799000, 1000;
Two observations:
You are doing 'SELECT *' do you need to fetch every column ? If you need only specific columns, you should label them because the temp table of 1000 rows could be larger than you really need.
The WHERE and ORDER BY clauses usually give away performance issues or make table design shine. You need to create a mechanism that will speed up the gather of keys before gathering data.
In light of these two observations, there are two major changes you must make:
MAJOR CHANGE #1 : Refactor the query
Redesign the query so that
- keys are gathered from the index
- only 1000 or them are collect
- joined back to the main table
Here is the new query which does these three things
SELECT large_table.* FROM
large_table INNER JOIN
(
SELECT hotspot_id,discovered_at
FROM large_table
WHERE hotspot_id = 3000064
ORDER BY discovered_at
LIMIT 799000,1000
) large_table_keys
USING (hotspot_id,discovered_at);
The subquery large_table_keys gathers the 1000 keys you need. The result from the subquery is then INNER JOINed to large_table. So far, the keys are retrieved instead of whole rows. That's still 799,000 rows to read through. There is a better way to get those keys, which leads us to...
MAJOR CHANGE #2 : Create Indexes that Support the Refactored Query
Since the refactored query only features one subquery, you only need to make one index. Here is that index:
ALTER TABLE large_table ADD INDEX hotspot_discovered_ndx (hotspot_id,discovered_at);
Why this particular index ? Look at the WHERE clause. The hotspot_id is a static value. This makes all hotspot_ids form a sequential list in the index. Now, look at the ORDER BY clause. The discovered_at column is probably a DATETIME or TIMESTAMP field.
The natural order this presents in the index is as follows:
- Index features a list of hostpot_ids
- Each hotspot_id has an ordered list of discovered_at fields
Making this index also eliminates doing internal sorting of temp tables.
Please put these two major changes in place and you will see a difference in running time.
Give it a Try !!!
UPDATE 2011-08-25 08:15 EDT
I looked at your indexes. You still need to create the index I suggested.
Give ssh
the mysqldump
command to run but don't redirect it to a file. That will bring stdout
from the mysqldump
back to your local machine where you can redirect that to a local file.
ssh -i my_rsa_key my_user@my_domain.tld 'mysqldump -u my_db_user -pmy_db_password my_db' > /local/path/to/store/backup.sql
Best Answer
You can redirect the output of any command -- not just MySQL -- by using your shell's i/o redirection operators. For example, in bash:
This will launch the MySQL command line client, connect it to "mydb" on the local system (assuming you have access), read SQL commands from the file
commands.sql
and dump all the output to/dev/null
.If you wanted to save the output for review after the fact, you could redirect it to a file rather than to
/dev/null
:The
2>&1
redirectsstderr
as well asstdout
. If you wanted to see any errors on your terminal, you would only redirectstdout
: