Enable Logging of Slow Queries (Slow Query Log) in MySQL Database Įjungti registravimas Slow queries (Žemas Užklausa Prisijungti) MySQL duomenų bazė
One of the main requirements for a fast Vienas iš pagrindinių reikalavimų greitai web server interneto serveryje is to has efficient and effective SQL statements or queries that are optimized. yra yra veiksminga ir efektyvi SQL arba užklausų, optimizuoti. 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 Bet ne optimalus SQL (Structured Query Language) komandos arba pareiškimus, kad pernelyg ilgai arba ilgas laiko atlikti bus panaudoti daug sistemos išteklių, todėl 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. Duomenų bazės vykdyti lėčiau, tada daugiau užklausų vėlavimu eilės aukštyn ir ryšį ribą, lankytojų atmestas arba atsisakytus ryšį. In worst case scenario, your web server will go down as well, or continuously underperform. Į blogiausio atvejo scenarijų, savo interneto serverio vyks taip pat, arba nuolat nepakankamai veiksmingai. 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. Šiuo atveju yra ypač aktualu, kai naudojate MyISAM lentelės tipo, kurį naudoja stalo lygio fiksavimo vietoj eilutės lygio fiksavimo į didelį eismo svetainėje.
Sometime, a single SQL query may be the cause of all the server's problems. Kartais, vienu SQL užklausa gali sukelti visų serverio problemos. 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 turi įmontuotą funkciją surinkimo lėtai užklausa prisijungti arba nustatyti klausimus, kurie nėra optimalus ir ilgai užtrukti iki pabaigos, kuri leidžia prisijungti visiems lėtai veikia užklausų perėmė apibrėžto skaičiaus sekundžių vykdyti MySQL duomenų bazės į failas. Slow query log is not activated or on by default MySQL installation, thus it is one of the less-used logs. Žemas užklausą žurnalo nėra aktyvuotas arba pagal nutylėjimą MySQL įrenginys, todėl vienas iš mažiau naudojamų žurnalų.
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: Kad lėtai užklausą prisijungti, paprasčiausiai pridėkite šią eilutę į MySQL konfigūracijos failo (my.cnf arba my.ini) ir paleiskite serverį MySQL:
log-slow-queries log-lėtai užklausos
or arba
log-slow-queries = [path to the log file] log-lėtai queries = [kelias iki failo žurnalo]
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. Pakeisti [kelią iki failo žurnalo] realiam kelią lėtai užklausą žurnalo failą norite MySQL rašyti žurnalą, kuris yra pasirinktinai vertės.
Or you can start mysqld with with the –log-slow-queries[=file_name] option to enable the slow query log. Arba galite pradėti name su su-log-lėtai užklausas [= nazwa_pliku] įjungti lėta užklausa prisijungti. 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. Abiem syntaxes, jei nepavyksta prisijungti failo pavadinimas yra nurodyta, numatytasis pavadinimas host_name-slow.log, saugomi MySQL duomenų rinkmeną kataloge. If a filename is given, but not as an absolute pathname, the server writes the file in the data directory too. Jei failo pavadinime yra teikiama, bet ne kaip absoliutus kelias, serveris įrašo failą kataloge duomenų per.
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. Įjungus lėtai užklausą prisijungti, MySQL bus sukurti, surinkimo ir prisijunkite prie log failą su SQL, kad prireikė daugiau nei long_query_time sekundžių vykdyti, kuri yra pagal nutylėjimą nustatytas 10 sekundžių. The time to acquire the initial table locks is not counted as execution time. Metu įgyti pradinės lentelės spynos nėra skaičiuojami kaip vykdymo laiką. 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. name rašė pareiškimą lėtai užklausa prisijungti po to, kai jis buvo įvykdytas ir po visų spynos buvo išleista, todėl prisijungti tvarka gali skirtis nuo vykdymo tvarka.
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. Tada galite patikrinti visų SQL užklausų kad užtruko ilgiau nei iš anksto apibrėžto skaičiaus sekundžių (10 sekundžių pagal nutylėjimą) į host_name-slow.log, ir imtis būtinų veiksmų siekiant optimizuoti SQL pareiškimus. 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ėtai užklausa prisijungti papasakos Jums apie tai buvo laikas užklausą baigtas, kaip ilgai užklausa prireikė skaičiuoti, kiek laiko ji ėmėsi užtikrinti spynos, kiek eilučių buvo išsiųsti atgal, kaip rezultatas, kiek eilučių buvo ištirti, siekiant nustatyti rezultatas, o duomenų bazė buvo naudojamas, ir faktinį užklausą 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 atminti, kad SQL užklausos esančius prisijungti jau optimalų, bet įgyvendinamos lėtai dėl sistemos ištekliai buvo panaudoti pagal faktinį lėtai, kad reikia gerai suderinti.
IMPORTANT : The page is machine translated and provided "as is" without warranty. DĖMESIO: Šis puslapis yra mašina išvertė ir pateikiama "kaip yra" be garantijų. Machine translation may be difficult to understand. Mašininio vertimo, gali būti sunku suprasti. Please refer to Remkitės original English article originalas anglų straipsnis whenever possible. jei įmanoma.
Related Articles Susiję straipsniai
- Change or Set MySQL Long Query Time Value for log-slow-queries Keisti arba Nustatyti MySQL Ilgalaikė Query Time Vertė log-lėtai užklausos
- WordPress MySQL SQL Query Error in WPDB Class WordPress MySQL, SQL Query Klaida WPDB klasė
- How to Find and Replace Text in MySQL Database using SQL Kaip rasti ir pakeisti tekstą MySQL duomenų bazėmis, naudojant SQL
- Check and Optimize MySQL Database Automatically with Crontab/Cron Pabandykite ir Optimizuokite MySQL Database Automatiškai su Crontab / Cron
- 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 Šalinti arba TRIMs Pirmasis ar pastaruosius keletą simbolių MySQL duomenų bazę su SQL
- Enable MySQL InnoDB Storage Engine Support in XAMPP Installation Įjungti MySQL InnoDB Saugojimo Variklis Pagalba XAMPP Diegimas
- Change and Reset MySQL root Password Kaitos ir naujo MySQL root Password
- You Are Not Authorized to Execute SQL Queries in vBulletin Maintenance Jums neleidžiama vykdyti SQL užklausų pagal vBulletin priežiūra
- Oracle Database Link Oracle Nuoroda










































July 18th, 2009 02:23 18 liepa 2009 02:23
when you go to my.cf you will see that by default the lines Kai jūs einate į my.cf pamatysite, kad pagal nutylėjimą linijų
log_slow_queries = /var/log/mysql/mysql-slow.log & log_slow_queries = / var / log / mysql / mysql-slow.log &
long_query_time = 1 long_query_time = 1
are commented out, however, the next line yra komentarų, tačiau, kitą eilutę
log-queries-not-using-indexes log-užklausų-ne-naudojant-indeksus
is not, so if you enable slow query logging then by default all queries not using indexes will show up in that log. nėra, todėl, jei leidžia lėtai užklausą prisijungiant tada pagal nutylėjimą visų užklausų nenaudojate indeksus bus rodomi tame žurnale. For most DBs this will be a ton of data which is why your logs are filling up so quickly. Daugumai duomenų bazę tai bus t duomenų, todėl jūsų žurnalai pildo taip greitai.
My suggestion is comment out this line Mano pasiūlymas yra jame šią eilutę
log-queries-not-using-indexes log-užklausų-ne-naudojant-indeksus
and change the long_query_time value to something low like 1 or 2, this should give you some meaningful results with which to start from. ir pakeisti long_query_time vertės kažkas mažo kaip 1 arba 2, tai turi duoti jums keletą reikšmingus rezultatus, kurie turi būti pradėti nuo.
If you still get no results it might be that you have no slow queries in which case you should uncomment out the line Jei vis dar negaunate rezultatų, gali būti, kad jūs neturite lėtai užklausų Tokiu atveju jums reikėtų odkomentować iš linijos
log-queries-not-using-indexes log-užklausų-ne-naudojant-indeksus
and start trying to index some of those queries. ir pradėti bando indeksas kai kurie iš šių klausimų.
hope that helps someone tikiuosi, kad padeda kažkas
-Kain -Kain
February 20th, 2009 21:29 Vasaris 20, 2009 21:29
I use MONyog Query analyzer to analyze slow queries. Aš naudoju MONyog Query Analyzer analizė lėtai užklausas. It works flawlessly. Jis dirba nepriekaištingai.
December 19th, 2008 19:37 Gruodžio 19 d. 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. Mes negalime patvirtinti šio - Aš leido lėtai loggin į atitinkamus konfigūracijos failo (debian lenny, mysql 5,0 naujausia), nes aš HAD "kai kurių" lėtas queries anksčiau.
After enabling there are thousands of “slow queries” being logged – The slow limit is set to the default of 10 sec. Įjungus yra tūkstančiai "lėtas užklausas" registruojami - Lėtai limitas yra nustatytas pagal nutylėjimą yra 10 sekundžių. 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 Tai tikrai nesąmonė, nes negali būti> 10sec užklausą, kai visą puslapį yra apskaičiuojamas pagal Php, pervedamas per tinklą ir lydyti į kliento naršyklę, po 5 sekundžių
greetings Marcus sveikinimai Marcus
November 1st, 2008 18:48 Lapkričio 1 d. 2008 18:48
i try to do that but this message appeared Aš stengiuosi daryti, bet šį pranešimą paaiškėjo,
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] Fatal error: Prašome perskaityti skyrelyje "Saugumas" vadovu ir sužinokite, kaip paleisti mysqld kaip root!
081101 5:34:51 [ERROR] Aborting 081101 5:34:51 [KLAIDA] Aborting
081101 5:34:51 [Note] mysqld: Shutdown complete 081101 5:34:51 [Pastaba] name: shutdown užpildyti
what should i do in this case? Ką daryti tokiu atveju?
January 23rd, 2007 00:22 Sausis 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. [...] Jei įjungsite lėtai užklausų istorija MySQL duomenų bazių serveris, jūs pastebėsite, kad iš lėto užklausą žurnalo faile yra tik SQL pareiškimus ir prašymus, kad prireikė daugiau nei query_time 10 sekundžių atlikti arba paleisti. This is the default value or query time threshold for log_slow_queries function, which is 10 seconds. Tai numatytoji vertė arba užklausą laiko riba log_slow_queries funkciją, kuri yra 10 sekundžių. 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 sekundžių yra per daug ilgas SQL užklausą, todėl vertė gali būti per didelis fiksuoti bet kokius reikšmingus duomenis. You can alter or change the slow query time to lower value or number of seconds. Galite pakeisti ar pakeisti lėtai užklausą laiko žemesniąją vertę arba skaičių sekundžių. 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 galite nustatyti naują long_query_time į MySQL konfigūracijos failą, būtent my.cnf arba my.ini, paprastai esančių / etc. Simply add the following line to the configuration file: [...] Tiesiog pridėkite šią eilutę failo konfigūracija: [...]