Enable Logging of Slow Queries (Slow Query Log) in MySQL Database Enable iegrāmatošana Lēna vaicājumu (Lēna Query Log) in MySQL Database
One of the main requirements for a fast Viena no galvenajām prasībām, lai ātri web server tīmekļa serveris is to has efficient and effective SQL statements or queries that are optimized. ir, ir efektīvs un efektīvu SQL paziņojumus vai jautājumiem, kas ir optimizēta. Any non-optimal SQL (Structured Query Language) commands or statements that take too long or lengthy time to execute will use up a lot of system resources, causing Nesaistītam-optimālā SQL (Strukturēts Query Language) komandas vai paziņojumus, ka pārāk garš vai garš laiks izpildīt būs izmantot daudz sistēmas resursu, izraisot MySQL MySQL database to run slower, and then more and more queries backlogs queuing up, and when connection limit is reached, visitors are been denied or refused connection. datu bāzi, lai vadītu lēnāka, un pēc tam arvien vairāk queries uzkrāšanos ierindošana augšu, un tad, kad savienojumu limits ir sasniegts, apmeklētāji tiek liegta vai atsaka savienojumu. In worst case scenario, your web server will go down as well, or continuously underperform. In sliktākajam scenārijam, jūsu tīmekļa servera dosies uz leju, kā arī, vai nepārtraukti underperform. The case is especially true when you are using MyISAM table type which uses table-level locking instead of row-level locking in a high traffic website. Šī lieta ir īpaši patiesi tad, ja jūs izmantojat MyISAM galda tipa, kas izmanto galda līmeņa bloķēšanas nevis rinda līmeņa bloķēšana augstu satiksmes mājas lapā.
Sometime, a single SQL query may be the cause of all the server's problems. Dažkārt, vienotu SQL query var izraisīt visu servera problēmas. MySQL has built-in functionality to capture slow query log or identify queries that are not optimal and take a long time to finish, which allows you to log all slow running queries which took over defined number of seconds to execute by MySQL database engine to a file. MySQL ir iebūvēts funkcionalitāti uztveršanas lēns query log vai identificētu vaicājumiem, kas nav optimāli un nepieciešams ilgs laiks, lai pabeigtu, kas ļauj jums pieteikties visi lēnas skriešanas queries kas pārņēma noteikts skaits sekundēs izpildīt ar MySQL datubāzi motors ar fails. Slow query log is not activated or on by default MySQL installation, thus it is one of the less-used logs. Lēna query log nav aktivizēts vai pēc noklusējuma MySQL uzstādīšana, tādējādi tas ir viens no mazāk izmantotajām apaļkokiem.
To enable slow query log, simply add the following line to MySQL configuration file (my.cnf or my.ini), and then restart the MySQL server: Lai aktivizētu lēno vaicājumu žurnālu, vienkārši pievieno šādu pozīcija MySQL konfigurācijas failu (my.cnf vai my.ini), un pēc tam restartējiet MySQL serveris:
log-slow-queries log-lēni queries
or vai
log-slow-queries = [path to the log file] log-lēni queries = [ceļš uz log failu]
Replace [path to the log file] with actual path to the slow query log file you want the MySQL to write the log to, which is the optional value. Aizstāt [ceļš uz log file] ar faktisko ceļu uz lēnas query log failu vēlaties, MySQL rakstīt žurnāla, kas ir fakultatīva vērtība.
Or you can start mysqld with with the –log-slow-queries[=file_name] option to enable the slow query log. Vai arī jūs varat sākt mysqld ar ar-log-lēni queries [= FILE_NAME] opciju, lai varētu lēni query žurnālu. In both syntaxes, if not log file name is specified, the default name is host_name -slow.log, stored in the MySQL data file directory. Abos syntaxes, ja nav log faila nosaukums ir norādīts, pēc noklusējuma nosaukums ir host_name-slow.log, uzglabā ar MySQL datu failu direktoriju. If a filename is given, but not as an absolute pathname, the server writes the file in the data directory too. Ja filename ir norādīts, bet ne par absolūtu pathname, serverī raksta failu datu directory too.
After enabling slow query log, MySQL will create, capture and log to the log file with all SQL statements that took more than long_query_time seconds to execute, which is by default set to 10 seconds. Pēc ļaujot lēni query log, MySQL radīs, uztveršanas un žurnālu log failu ar visiem SQL apgalvojumiem, kas bija vajadzīgi vairāk nekā long_query_time sekundēs izpildīt, ko pēc noklusējuma iestatīta uz 10 sekundes. The time to acquire the initial table locks is not counted as execution time. Laika iegūt sākotnējo tabulu slēdzenes nav kā izpildes laiku. mysqld writes a statement to the slow query log after it has been executed and after all locks have been released, so log order might be different from execution order. mysqld raksta par to lēni query log pēc tam, kad tas ir izpildīts, un pēc tam, kad visi slēdzenes ir atbrīvotas, tā log rīkojuma starpniecību, var būt atšķirīgs no aresta rīkojumu.
You can then examine all the SQL queries that took longer than the pre-defined number of seconds (10 seconds by default) in the host_name -slow.log, and then take the necessary steps to optimize the SQL statements. Pēc tam jūs varat pārbaudīt visas SQL vaicājumi, ņēma ilgāk kā iepriekš noteikts skaits sekundes (10 sekundes pēc noklusējuma), kas host_name-slow.log, un pēc tam veic vajadzīgos pasākumus, lai optimizētu SQL paziņojumus. The slow query log will tell you about what was time the query completed, how long the query took to run, how long it took to secure its locks, how many rows were sent back as a result, how many rows were examined to determine the result, which database was used, and the actual query itself. Lēnā query log pateiks Jums par to, kas bija laikā, kad query pabeigta, cik ilgi query took darboties, cik ilgi tas aizņēma, lai nodrošinātu savu slēdzenes, cik rindas tika nosūtītas atpakaļ, kā rezultātā, cik daudz rindas tika pārbaudīti, lai noteiktu rezultātu, kas datu bāzē tika izmantota, un par faktisko query pati. But bear in mind that a SQL query contained in the log may have already optimum, but executed slowly due to the system resources been used up by the actual slow statement that need to be fine tuned. Bet jāņem vērā, ka SQL vaicājums, kas ietverti log jau varētu būt optimāla, bet izpilda lēni, ņemot vērā sistēmas resursu tika izmantoti ar faktisku lēns paziņojumu par to, ka ir jābūt smalka noregulē.
IMPORTANT : The page is machine translated and provided "as is" without warranty. SVARĪGI: Šī lapa ir mašīna tulkoto un ar nosacījumu ", kas ir" bez garantijas. Machine translation may be difficult to understand. Machine translation var būt grūti saprast. Please refer to Lūdzu, skatiet original English article oriģināls angļu rakstu whenever possible. kad vien iespējams.
Related Articles Saistītie raksti
- Change or Set MySQL Long Query Time Value for log-slow-queries Maina vai Set MySQL Long Query Time Vērtība, kam log-lēni queries
- WordPress MySQL SQL Query Error in WPDB Class WordPress MySQL SQL vaicājumu Kļūda WPDB klase
- Check and Optimize MySQL Database Automatically with Crontab/Cron Pārbaudiet un Optimizējiet MySQL Database Automātiski ar Crontab / Cron
- How to Find and Replace Text in MySQL Database using SQL Kā, lai atrastu un aizstātu tekstu MySQL datu bāzē, izmantojot SQL
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL Database Performance Tuning Best Practices Video Tutorial
- Remove or Trim First or Last Few Characters in MySQL Database with SQL Noņemt vai Trim Pirmā vai pēdējo rakstzīmes MySQL Database ar SQL
- Enable MySQL InnoDB Storage Engine Support in XAMPP Installation Enable MySQL InnoDB Storage Engine Atbalsts XAMPP Installation
- Change and Reset MySQL root Password Pārmaiņām un Reset MySQL root parole
- You Are Not Authorized to Execute SQL Queries in vBulletin Maintenance Jums nav tiesību Execute SQL vaicājumu in vBulletin Maintenance
- Oracle Database Link Oracle Database Link










































February 20th, 2009 21:29 Februāris 20, 2009 21:29
I use MONyog Query analyzer to analyze slow queries. I use MONyog Query analizatorā analizēt lēns vaicājumiem. It works flawlessly. It works flawlessly.
December 19th, 2008 19:37 Decembris 19, 2008 19:37
I can't really confirm this - I enabled slow loggin in the appropiate config file (debian lenny, mysql 5.0 latest) because I HAD “some” slow queries before. Es nevaru tiešām apstiprina šo - Es ļāva lēns loggin pie attiecīgā config failu (Debian Lenny, mysql 5,0 latest), jo man bija "dažas" lēni queries iepriekš.
After enabling there are thousands of “slow queries” being logged - The slow limit is set to the default of 10 sec. Pēc ļauj tūkstošiem "lēni queries" ir pieteicies - lēnā ierobežojums ir noteikts ar to, 10 sec. This is really nonsense as there can't be a >10sec query when the whole page is being calculated, by php, tranferred over the net and rendered on the client browser in under 5 sec Tas ir tiešām absurds, jo nevar būt> 10sec vaicājumam, kad visas lapas tiek aprēķināta ar php, tranferred pār tīklu un snieguši klienta pārlūkprogramma in 5 sec
greetings Marcus greetings Marcus
November 1st, 2008 18:48 1 novembris, 2008 18:48
i try to do that but this message appeared i try to darīt, bet šo ziņojumu parādījās
081101 5:34:51 [ERROR] Fatal error: Please read “Security” section of the manual to find out how to run mysqld as root! 081101 5:34:51 [ERROR] Fatāla kļūda: Lūdzu, izlasiet "Drošība" sadaļā rokasgrāmatu, lai uzzinātu to, kā vadīt mysqld kā sakne!
081101 5:34:51 [ERROR] Aborting 081101 5:34:51 [ERROR] Aborting
081101 5:34:51 [Note] mysqld: Shutdown complete 081101 5:34:51 [Piezīme] mysqld: shutdown pabeigt
what should i do in this case? Kas man ir jādara šajā gadījumā?
January 23rd, 2007 00:22 Janvāris 23, 2007 00:22
[...] If you enable slow queries log of MySQL database server, you will notice that from the slow query log file contains only SQL statements and queries that took more than query_time of 10 seconds to execute or run. [...] Ja jūs iespējojat lēni queries log no MySQL datu bāzes servera, jūs ievērosiet, ka no lēni query log fails satur tikai SQL pārskati un jautājumiem, kas prasīja vairāk nekā query_time 10 sekundes, lai veiktu vai darboties. This is the default value or query time threshold for log_slow_queries function, which is 10 seconds. Šī ir noklusējuma vērtības vai vaicājumu laika slieksni log_slow_queries funkcija, kas ir 10 sekundes. 10 seconds is way too long for a SQL query to complete, so the value may be too high to capture any meaningful data. 10 sekundes ir pārāk ilgi uz SQL query, lai pabeigtu, tā vērtība var būt pārāk augstas, lai iegūtu jebkādu nozīmīgu informāciju. You can alter or change the slow query time to lower value or number of seconds. Varat mainīt vai mainīt lēns query laiku zemāko vērtību vai skaitu sekundes. You can set a new long_query_time in the MySQL configuration file, namely my.cnf or my.ini, normally located in /etc directory. Jūs varat uzstādīt jaunu long_query_time ar MySQL konfigurācijas failu, proti my.cnf vai my.ini, parasti atrodas / etc direktorijā. Simply add the following line to the configuration file: [...] Vienkārši pievienot šādas līnijas līdz konfigurācijas failu: [...]