Skip to content Skip to content


How to setup slow query logging in MySQL Kā setup lēno vaicājumu ielogojoties MySQL

Linux

If you run or administer a production MySQL server it's quite likely that it sometimes runs a little slow, and can be a very time consuming effort to figure out why. Ja jums vai pārvaldīt ražošanas MySQL serveri, to ir diezgan iespējams, ka tā dažkārt ilgst mazliet lēni, un tā var būt ļoti laikietilpīgu pūles, lai saprastu, kāpēc. To be able to pinpoint the query that slows the DB down can be hard to track down. Lai varētu precizēt vaicājumu, kas palēnina DB noteikti var būt grūti izsekot. MySQL has an option to help you out. MySQL ir iespēja jums palīdzēt out. It comes with an option to log slow queries. Tas nāk ar iespēju pieteikties lēni queries. This way when you find your database server running slower than usual you can open this log file in a text editor and see what queries are running slow. Tādā veidā, kad jūs atradīsiet savu datu bāzi serverī, kurā darbojas lēnāk nekā parasti, varat atvērt šo log failu teksta redaktorā un redzēt kādi jautājumi darbojas lēni. Let's look at how to set this up. Apskatīsim, kā noteikts šīs augšu.

First open your MySQL server's configuration file, my.cnf . Pirmā atvērtā Jūsu MySQL servera konfigurācijas failu, my.cnf. On Linux this should be in the /etc directory. Linux tam būtu jābūt / etc direktoriju. Look to see if the parameter log-slow-queries has already been set. Skatīties lai redzētu, vai parametrs log-lēni jautājumi jau ir noteikts. If not, then set it to something like this: Ja nē, tad noteikt tā, lai kaut kas līdzīgs šim:

log-slow-queries = /var/log/mysql/mysql-slow.log log-lēnas jautājumi = / var / log / mysql / mysql-slow.log

You also need to set the length of time before a query is fit to be considered a slow query . Jums arī vajadzēs noteikt laiku, pirms vaicājums ir gatavs jāuzskata lēni vaicājumu. On my server I have set it to 30 seconds, like this: Uz mana servera Man ir noteikts līdz 30 sekundēm, piemēram:

long_query_time = 30 long_query_time = 30

Restart your MySQL server, and then watch the mysql-slow.log file. Restartējiet MySQL serverim, un tad skatīties mysql-slow.log failu. Whenever a query takes longer to complete than 30 seconds, or whatever you set in my.cnf , the query will be logged in mysql-slow.log. Ikreiz, kad vaicājums aizņem ilgāku laiku, lai pabeigtu nekā 30 sekundes, vai kāds jūs noteikti my.cnf, vaicājums būs pieteicies mysql-slow.log. Now debugging MySQL queries should be a lot simpler and quicker for you. Tagad atkļūdošana MySQL queries būtu daudz vienkāršāk un ātrāk par jums. Do remember to check this file every once in a while. Vai atceries, lai pārbaudītu katru reizi šo failu laiku. What might help is to Kas varētu palīdzēt, ir setup a cron job setup cron darbs to mail you this file once every few days. uz jūsu šo failu reizi pāris dienās.

Posted in Posted in Linux Linux . .

Related Posts: Related Posts:

How to monitor MySQL in real-time with mytop Kā kontrolēt MySQL reālā laika mytop
How to remotely access your MySQL in a secure manner Kā attālināti piekļūt savam MySQL drošā veidā
Bash one liner – how to compress, move, and extract a directory Bash vienu starpliku - kā, lai saspiestu, pārvieto un ekstrakts katalogs
How to get a detailed MySQL status report Kā iegūt detalizētu MySQL statusa atskaiti
How to reset a lost MySQL root password Kā lai atjaunotu zaudēto MySQL root paroli

0 Responses 0 Atbildes

Stay in touch with the conversation, subscribe to the Uzturēt kontaktus ar sarunu, abonēt RSS feed for comments on this post RSS barību komentārus par šo ziņu . .



Some HTML is OK Daži HTML ir OK

or, reply to this post via vai, atbildot uz šo ziņu izmantojot trackback Trackback . .