Вы находитесь на странице: 1из 46

Optimizing MySQL Configuration

Peter Zaitsev,CEO Percona Live, Washington DC !anuary "# "

&gen'a
( ( ( ( &pproach to getting great MySQL Configuration )ypes of Configuration Options )oo*s to Configure MySQL Loo+ing at Most ,mportant Options

$$$%percona%com

-ut -efore We start


( .o$ many settings 'o you set in Config /i*e 0

$$$%percona%com

&*so
( .o$ usefu* 'o you thin+ MySQL Defau*t Configuration 0

$$$%percona%com

Configuration )uning -asics


( 1n'erstan' $hat you2re changing 3oog*e Copy4Paste $ithout thin+ing can 5e 5a' ( &voi' O5sessive )uning Disor'er Setting # settings $i** give 678 of possi5*e performance in 678 cases ( -e$are of 9Samp*e Configs: ,n MySQL 'istri5utions )hey are pretty out'ate' "3- of memory is 9huge: these 'ays 0 ;ight for Ce** Phone

$$$%percona%com

Most Options 'o not Sca*e


( 3oing to Server $ith <= memory you can2t >ust mu*tip*y a** configuration varia5*es "=

$$$%percona%com

?no$ Scope an' 1nit


( sort@5uffer@sizeA B3 WrongC sort@5uffer@size is set per connection ( ta5*e@cacheAB<M WrongC ta5*e@cache is set in e*ements not memory size%

$$$%percona%com

&voi' -asic Mista+es


( Setting varia5*es in $rong config fi*e 4etc4mysD*4my%cnf instea' of 4etc4my%cnf )hese 'epen' on Linu= Distro, -e$are ( Dup*icating Options Last option $i** overri'e previous*y set ( Eot +no$ing Synonyms table_cache is same as table_open_cache ( 1sing $rong section for option Server rea's FmysD*'G, c*ient FmysD*G

$$$%percona%com

Config Management Practices


( ?eep Config /i*es in Sync on 'ifferent servers Out of Sync config fi*es is freDuent cause of mista+es an' confusion ( ?eep ;ecor' of Changes Config fi*es un'er version contro* is great

$$$%percona%com

Why $ou*' set an option


( Sanity Chec+ Options Many 'o not impact Performance at a** ( 3enera* Options to set for .ar'$are an' Wor+*oa' /e$ of them ( Specia* Options Defau*ts genera**y fine, un*ess your circumstances are very specia*

$$$%percona%com

Do not *et MySQL S$ap


( &**ocating too much memory an' having MySQL s$apping is a *ot $orse than not using a** memory ( Monitor s$apping Hsi4so from vmstat c*ose*yI ( Start $ith safe 5uffer va*ues an' increase them gra'ua**y if a *ot of memory stays free

$$$%percona%com

&utomate' Configuration )uning


( )oo*s $hich c*aim to create 5est configuration 5y *oo+ing at status varia5*es -e$are% ;ecommen'ations are often poor ( &'visory )oo*s )oo*s $hich chec+ your config fi*e for typica* mista+es an' omissions ( -asic configuration creation too*s Do not c*aim to 'o magic 5ut can get your starte' $ith 5etter configuration than 'efau*t

$$$%percona%com

mysDtuner
-------- General Statistics -------------------------------------------------[--] Skipped version check for MySQLTuner script [OK] Currently runnin supported MySQL version !"#"!$-rel#%"&-lo [OK] Operatin on '(-)it architecture -------- Stora e *n ine Statistics ------------------------------------------[--] Status+ ,-rchive -./. -0ederated ,1nno/. -1S-M -2/.Cluster [--] /ata in My1S-M ta)les+ $3G 4Ta)les+ #%&%5 [--] /ata in 1nno/. ta)les+ #G 4Ta)les+ 33&5 [--] /ata in M*MO67 ta)les+ 8. 4Ta)les+ %5 [99] Total fra :ented ta)les+ ##8 -------- Security 6eco::endations ------------------------------------------[99] ;ser <=< has no pass>ord set"

$$$%percona%com

MysD*tuner H"I
( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( JJJJJJJJ Performance Metrics JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ FJJG 1p forK 7L' #h #m "Ms H7MMM D FM6%" 6 DpsG, NM conn, )OK "#"-, ;OK <B-I FJJG ;ea's 4 WritesK 6L8 4 M8 FJJG )ota* 5uffersK <%M3 g*o5a* P "%LM per threa' H"## ma= threa'sI FO?G Ma=imum possi5*e memory usageK <%N3 H<#8 of insta**e' ;&MI FCCG S*o$ DueriesK L8 H< M47MMMI FO?G .ighest usage of avai*a5*e connectionsK 7<8 H #64"##I FO?G ?ey 5uffer size 4 tota* My,S&M in'e=esK <%#34 %M3 FO?G ?ey 5uffer hit rateK ##%#8 H<7- cache' 4 BM rea'sI FCCG Query cache is 'isa5*e' FO?G Sorts reDuiring temporary ta5*esK #8 H<<? temp sorts 4 B#M sortsI FCCG !oins performe' $ithout in'e=esK "77BN7 FCCG )emporary ta5*es create' on 'is+K < 8 H"7M on 'is+ 4 B M tota*I FO?G )hrea' cache hit rateK 6 8 HL6 ? create' 4 NM connectionsI FCCG )a5*e cache hit rateK "8 H ? open 4 76? opene'I FO?G Open fi*e *imit use'K M"8 H"?4N?I FO?G )a5*e *oc+s acDuire' imme'iate*yK 668 H<MBM imme'iate 4 <MBM *oc+sI FCCG ,nnoD- 'ata size 4 5uffer poo*K % 34"7B%#M
$$$%percona%com

mysD*tunerHMI
( ( ( ( ( ( ( ( ( ( ( ( ( JJJJJJJJ ;ecommen'ations JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ 3enera* recommen'ationsK ;un OP),M,ZE )&-LE to 'efragment ta5*es for 5etter performance &'>ust your >oin Dueries to a*$ays uti*ize in'e=es When ma+ing a'>ustments, ma+e tmp@ta5*e@size4ma=@heap@ta5*e@size eDua* ;e'uce your SELEC) D,S),EC) Dueries $ithout L,M,) c*auses ,ncrease ta5*e@cache gra'ua**y to avoi' fi*e 'escriptor *imits Qaria5*es to a'>ustK Duery@cache@size HRA NMI >oin@5uffer@size HR "N%#?, or a*$ays use in'e=es $ith >oinsI tmp@ta5*e@size HR BMI ma=@heap@ta5*e@size HR BMI ta5*e@cache HR <#6BI inno'5@5uffer@poo*@size HRA 3I

$$$%percona%com

ptJvaria5*eJa'visor
( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( S W&;E inno'5@f*ush@*og@at@tr=@commitJ K ,nnoD- is not configure' in strict*y &C,D mo'e% S EO)E inno'5@ma=@'irty@pages@pctK )he inno'5@ma=@'irty@pages@pct is *o$er than the 'efau*t% S EO)E *og@$arningsJ"K Log@$arnings must 5e set greater than a5orte' connections% to *og unusua* events such as

S EO)E ma=@connect@errorsK ma=@connect@errors shou*' pro5a5*y 5e set as *arge as your p*atform a**o$s% S W&;E o*'@pass$or'sK O*'Jsty*e pass$or's are insecure% S W&;E s*ave@net@timeoutK )his varia5*e is set too high% S EO)E inno'5@'ata@fi*e@pathK &utoJe=ten'ing ,nnoD- fi*es can consume a *ot of 'is+ space that is very 'ifficu*t to rec*aim *ater% S W&;E myisam@recover@optionsK myisam@recover@options shou*' 5e set to some va*ue such as -&C?1P,/O;CE to ensure that ta5*e corruption is notice'% S W&;E sync@5in*ogK -inary *ogging is ena5*e', 5ut sync@5in*og isn2t configure' so that every transaction is f*ushe' to the 5inary *og for 'ura5i*ity%

$$$%percona%com

too*s%percona%com

$$$%percona%com

)oo*s%percona%com

$$$%percona%com

Lets *oo+ at the options no$


( Different c*asses of optionsK 3enera* Options My,S&M ,nno'5 Qisi5i*ity an' Logging

$$$%percona%com

3etting Status Qaria5*es


( We refer to SHOW GLOBAL STATUS output in many 'escriptions ( Percona )oo*+it too ptJme=t is he*pfu* ( pt-mext -r -- mysqladmin ext -i !! -c" ( &5orte'@c*ients "N # #
&5orte'@connects 6#6 -in*og@cache@'is+@use M -in*og@cache@use "B"N7L -ytes@receive' <B7 N6#"BN -ytes@sent "#"6NM#<6<"B # # # 7N#6LB < LNNB # # # <76 M # NB L

$$$%percona%com

3enera* Options
( max_connections .o$ many connections to a**o$ 0 Watch max_#sed_connections status va*ue ( threa'@cache Cache to prevent e=cessive threa' creation 7#J ## is goo' va*ue% Watch threads_created ( table_cache$table_open_cache Cache of opene' ta5*e instances Sing*e ta5*e may have mu*tip*e entries Watch opene'@ta5*es status va*ue Start $ith <#6B MySQL $i** on*y use as nee'e' any$ay%
$$$%percona%com

3enera* Options
( open_%iles_limit My,S&M ta5*es reDuire up to " fi*e han'*ers Each connection is fi*e han'*er too Safe to set to B77M7 in most systems ( table_de%inition_cache Cache ta5*e 'efinitions HC;E&)E )&-LEI On*y one entry per ta5*e Watch Opened_table_de%initions Set to cover a** ta5*es un*ess 7#?P ta5*es

$$$%percona%com

3enera* Options
( bac&_lo' Eee' a'>ustment if many connections4sec "#<N is reasona5*e va*ue ( max_allo(ed_pac&et Limits ma=imum size of Duery Limits interna* string varia5*e size BM- is a goo' va*ue ( max_connect_errors Prevent pass$or' 5rute force attac+ Can cause 9.ost -*oc+e': error messages Qa*ue aroun' ###### is goo'
$$$%percona%com

3enera* Options
( s&ip_name_resol)e &voi' DES *oo+up on connection% /aster an' Safer Do not use host names in G*A+Ts ( old_pass(ords Shou*' EO) 5e ena5*e'% Wi** cause insecure pass$or' hash to 5e use'%

$$$%percona%com

3enera* Options
( lo'_bin Ena5*e for rep*ication an' point in time recovery Set to 9mysD*J5in: to avoi' 'efau*t naming ( sync_binlo' Ma+e -in*og 'ura5*e% Set to if have ;&,D $ith --1 or /*ash Can 5e rea**y performance +i**er $ith s*o$ 'rives% ( expire_lo'_days Purge o*' 5inary *ogs < H" $ee+sI is a goo' va*ue $ith $ee+*y 5ac+ups%
$$$%percona%com

3enera* Options
( tmp_table_si,e ( max_heap_table_si,e )ypica**y set to same va*ue H$or+*oa' 5ase'I -reated_tmp_dis&_tables status varia5*e -evare -LO-4)EO) fie*'s cause on 'is+ ta5*e $ith any size% ( q#ery_cache_si,e Ena5*e Duery cache on*y if it is teste' to provi'e significant gains Often causes sta**s an' contention Do not set over 7 "M$$$%percona%com

3enera* Options
( sort_b#%%er_si,e ,n memory 5uffer use' for sorting Watch sort@merge@passes Consi'er setting for session for *arge Dueries Qa*ues up to M- are goo' 'efau*t Large va*ues hurt performance of sma** Dueries ( .oin_b#%%er_si,e .e*ps performance of !oins $ith no in'e=es -etter get ri' of such !oins C NM- can 5e reasona5*e va*ue ( de%a#lt_stora'e_en'ine 1se this engine for ta5*es if not specifie'
$$$%percona%com

3enera* Options
( read_rnd_b#%%er_si,e -uffer for rea'ing ro$s in sorte' offer Specifies Ma=imum Qa*ue Qa*ues aroun' BM- often ma+e sense Do not mi= $ith read_b#%%er_si,e ( Tmpdir Specify *ocation of temporary 'irectory )mpfs often goo' choice un*ess very *arge temporary space is nee'e'%

$$$%percona%com

My,S&M options
( &ey_b#%%er_si,e Cache My,S&M ,n'e=es% Does Eot cache 'ata% 1p to M#8 of memory if using My,S&M on*y ( myisam@recover &utomatica**y repair corrupte' My,S&M ta5*es after crash% BA-/U012O*-3 is a goo' va*ue% ( myisam_sort_b#%%er_si,e -uffer use' for 5ui*'ing My,S&M in'e=es 5y Sort% NM-J"7BM- are goo' va*ues%

$$$%percona%com

My,S&M Options
( lo(_priority_#pdates &**o$ higher concurrency for SELEC)s May starve up'ate Dueries ( b#l&_insert_b#%%er_si,e -uffer to optimize -u*+ ,nserts Qa*ues of T of &ey_b#%%er_si,e ma+e sense Eote it is per connection va*ue (

$$$%percona%com

,nno'5 U Memory Settings


( innodb_b#%%er_pool_si,e )he most important setting% Often N#8P of memory is a**ocate' here% ( innodb_b#%%er_pool_instances ;e'uce contention% Set to <P in MySQL 7%7P ( innodb_lo'_b#%%er_si,e -uffer for *og fi*es% 3oo' Qa*ues <M-J "NM Eot on*y re'uce $rites 5ut he*p contention ( innodb_ib#%_max_si,e Contro* size of ,nsert 5uffer% Defau*t is V of -uffer poo*% Sma**er va*ues are goo' for SSD
$$$%percona%com

,nno'5 ,O Options
( innodb_%l#sh_lo'_at_trx_commit Contro* Dura5i*ity Af*ush an' syncW "Af*ushW #Aneither ( ,nno'5@f*ush@metho' Contro*s ho$ ,nno'5 Performs ,O O_45*3-T goo' va*ue for most servers ( innodb_a#to_lr#_d#mp Percona Server /eature to $armup Duic+*y M## Hsecon'sI is a goo' va*ue ( innodb_io_capacity Contro*s ,nno'5 &ssumption a5out Dis+ Performance% ,ncrease for faster 'rives%
$$$%percona%com

,nno'5 ,O Options
( innodb_read_io_threads ( innodb_(rite_io_threads Contro* num5er of threa's 'oing rea's an' $rites MySQL 7%7 has async ,O so very high va*ues might not 5e nee'e' < is goo' 'efau*t% .igher for *arge ,O systems% ( innodb_%l#sh_nei'hbor_pa'es Percona Server feature to contro* ho$ f*ushing $or+s Disa5*e Hset to #I for SSD
$$$%percona%com

Other ,nno'5 Options


( innodb_lo'_%ile_si,e Size of re'o *og fi*e% Larger *ogs 5etter performance 5ut *onger recovery% ( innodb_lo'_%iles_in_'ro#p Leave at " $hich is 'efau*t% ( innodb_%ile_per_table Store each ,nno'5 ta5*e in separate fi*e% 1sua**y 3oo' choice ( innodb6%orce Ena5*e so MySQL 'oes not start if ,nno'5 cou*' not initia*ize% Other$ise it might start 5ut error on access to a** ,nno'5 ta5*es%
$$$%percona%com

Other ,nno'5 Options


( inno'5@'ata@fi*e@path Settings for ,nno'5 System )a5*espace 1se one fi*e% Limit gro$th as you can2t shrin+ it ibdata 7 !87a#toextend7max7 !G ( inno'5@*oc+@$ait@timeout .o$ *ong to $ait for ro$ *eve* *oc+s 5efore 5ai*ing out 0 ( innodb_old_bloc&s_time .e*ps to ma+e 5uffer poo* scan resistant Qa*ues aroun' ### ma+e sense

$$$%percona%com

Other ,nno'5 Options


( innodb_%ile_%ormat Which fi*e format ,nno'5 $i** use 9&nte*ope: is 'efau*t *egacy format 9-arracu'a: a**o$s to use ne$ features *i+e compression ( innodb_stats_on_metadata 1p'ate statistics on meta 'ata access Such as ,nformation@schema Dueries )ypica**y 5est 'isa5*e' for more $or+*oa's Set to # ,nno'5 $i** sti** refresh stats $hen ta5*e changes significant*y
$$$%percona%com

Qisi5i*ity Options
( per%ormance_schema Ena5*e Performance Schema in MySQL 7%7P Watch potentia* overhea'% ( lo'_slo(_q#eries Ena5*e S*o$ Query Log% O*' 5ut very he*pfu*% ( lon'_q#ery_time Especia**y $ith *ong@Duery@time set to # perio'ica**y to get samp*e of the *oa' ( lo'_slo(_)erbosity6%#ll 3et a *ot more 'ata a5out Dueries in Percona Server
$$$%percona%com

Qisi5i*ity Options
( lo(_(arnin's69 3et $arnings a5out 'isconnects an' other minor issues in error *og% More information 5ut it can get spammy ( #serstat_r#nnin'6 3et a'vance' )a5*e an' ,n'e= usage statistics in Percona Server an' MariaD-

$$$%percona%com

Summary
( ( ( ( Many Options to chose from C &n' these are se*ecte' 9fe$: C*ose to <## varia5*es avai*a5*e ,n *atest versions ;emem5er in most cases you 'o not nee' to tune more than a fe$ ( Consi'er starting $ith config fi*e generate' 5y httpK44too*s%percona%com &t *east it $i** sho$ you $hich options to pay attention to first%

$$$%percona%com

Main -o'y S*i'es


( 1se this *ayout for the main 5o'y of your presentation ( ?eep the fo**o$ing s*i'es at the en' of your presentationK
( Percona Live DC Sponsors ( &nnua* MySQL Conference X E=po ( Percona )raining H" s*i'esI ( Your Contact ,nformation ( Percona Live C*osing S*i'e $ith no te=t inserte' for QX& perio'
$$$%percona%com

Percona Live DC Sponsors


Me'ia Sponsor

/rien's of Percona Sponsor

$$$%percona%com

MySQL Conference X E=po "# "


Presented by Percona Live
)he .yatt ;egency Santa C*ara X Santa C*ara Convention Center

&pri* #thJ "th, "# " )utoria*s X ,nitia* -rea+out Sessions &nnounce'
httpK44$$$%percona%com4a5outJus4pressre*eases4perconaJ*iveJmysD*JconferenceJ an'Je=poJhea'sJtoJsantaJc*araJca*iforniaJapri*J #J "J"# "4

/eature' Spea+ers
Mar+ Ca**aghan H/ace5oo+I, !eremy Za$o'ny HCraigs*istI, Marten Mic+os HEuca*yptus SystemsI Sarah Eovotny H-*ue 3ec+oI, Peter Zaitsev HPerconaI, -aron Sch$artz HPerconaI

Learn More at $$$%percona%com4*ive4mysD*JconferenceJ"# "4


$$$%percona%com

Want More MySQL )raining0


Percona )raining in Washington DC Ee=t Wee+ January 16th-19th, 2012 MySQL Wor+shops
MySQL Deve*opers )raining J Mon'ay MySQL D-& )raining J )ues'ay MySQL ,nnoD- 4 OtraD- J We'nes'ay MySQL Operations U )hurs'ay

1se Discount co'e DCPLM# to save M#8


Qisit httpK445it%*y4'cJtraining

$$$%percona%com

1pcoming Percona MySQL )raining


Washington, DC U January 16, 2012 Qancouver, Cana'a J February 6, 2012 /ran+furt, 3ermany J February 13, 2012 ,rvine, C& U February 14, 2012 Denver, CO J February 20, 2012 San /rancisco, C& J March 12, 2012 &ustin, )O J March 19, 2012
Qisit httpK44percona%com4training

$$$%percona%com

Peter Zaitsev !" ercona#co$


%e&re 'irin() ***# ercona#co$+about-us+careers+

$$$%percona%com4*ive

Вам также может понравиться