Tải bản đầy đủ

OReilly high performance MySQL apr 2004 ISBN 0596003064










TableofContents
Index
Reviews
ReaderReviews
Errata
Academic

HighPerformanceMySQL
ByDerekJ.Balling,JeremyZawodny

Publisher :O'Reilly
PubDate :April2004

ISBN :0-596-00306-4
Pages :294
Slots :1.0


InHighPerformanceMySQLyouwilllearn
aboutMySQLindexingandoptimizationin
depthsoyoucanmakebetteruseofthese
keyfeatures.Youwilllearnpractical
replication,backup,andload-balancing
strategieswithinformationthatgoesbeyond
availabletoolstodiscusstheireffectsinreallifeenvironments.Andyou'lllearnthe
supportingtechniquesyouneedtocarryout


thesetasks,includingadvanced
configuration,benchmarking,and
investigatinglogs.











TableofContents
Index
Reviews
ReaderReviews
Errata
Academic

HighPerformanceMySQL
ByDerekJ.Balling,JeremyZawodny

Publisher :O'Reilly


PubDate :April2004
ISBN :0-596-00306-4
Pages :294
Slots :1.0



Copyright

Preface
TheBasicLayoutofThisBook

SoftwareVersionsandAvailability




ConventionsUsedinThisBook




HowtoContactUs

UsingCodeExamples
Acknowledgments


Chapter1.BackToBasics
Section1.1.BinaryVersusCompiled-From-SourceInstallations

Section1.2.ConfigurationFiles



Section1.3.TheSHOWCommands


Chapter2.StorageEngines(TableTypes)
Section2.1.MySQLArchitecture





Section2.2.LockingandConcurrency




Section2.3.Transactions



Section2.5.TheStorageEngines

Section2.4.SelectingtheRightEngine


Chapter3.Benchmarking
Section3.1.TheImportanceofBenchmarking

Section3.2.BenchmarkingStrategies



Section3.3.BenchmarkingTools


Chapter4.Indexes
Section4.1.IndexingBasics

Section4.2.IndexStructures




Section4.3.IndexesandTableTypes
Section4.4.IndexMaintenance


Chapter5.QueryPerformance
Section5.1.QueryProcessingBasics

Section5.2.OptimizerFeaturesandOddities




Section5.3.IdentifyingSlowQueries



Section5.5.StupidQueryTricks

Section5.4.InfluencingMySQLwithHints


Chapter6.ServerPerformanceTuning
Section6.1.Performance-LimitingFactors

Section6.2.RAID




Section6.3.OperatingSystem
Section6.4.Techniques


Chapter7.Replication
Section7.1.ReplicationOverview

Section7.2.ConfiguringReplication




Section7.3.UndertheHood




Section7.5.AdministrationandMaintenance



Section7.7.TheFutureofReplication

Section7.4.ReplicationArchitectures
Section7.6.CommonProblems


Chapter8.LoadBalancingandHighAvailability
Section8.1.LoadBalancingBasics

Section8.2.ConfigurationIssues






Section8.3.ClusterPartitioning
Section8.4.HighAvailability
Chapter9.BackupandRecovery
Section9.1.WhyBackups?






Section9.2.ConsiderationsandTradeoffs



Section9.4.RollingYourOwnBackupScript

Section9.3.ToolsandTechniques


Chapter10.Security
Section10.1.AccountBasics

Section10.2.TheGrantTables




Section10.3.GrantandRevoke




Section10.5.NetworkSecurity



Section10.7.MySQLinachrootedEnvironment

Section10.4.OperatingSystemSecurity
Section10.6.DataEncryption


AppendixA.TheSHOWSTATUSandSHOWINNODBSTATUSCommands
SectionA.1.SHOWSTATUS

SectionA.2.SHOWINNODBSTATUS


AppendixB.mytop
SectionB.1.Overview

SectionB.2.Gettingmytop




SectionB.3.ConfigurationandUsage
SectionB.4.CommonTasks


AppendixC.phpMyAdmin
SectionC.1.TheBasics

SectionC.2.PracticalExamples




Colophon
Index


Copyright©2004O'ReillyMedia,Inc.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reilly&Associatesbooksmaybepurchasedforeducational,
business,orsalespromotionaluse.Onlineeditionsarealso
availableformosttitles(http://safari.oreilly.com).Formore
information,contactourcorporate/institutionalsales
department:(800)998-9938orcorporate@oreilly.com.
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
HighPerformanceMySQL:Optimization,Backups,Replication,
andLoadBalancingtheimageofasparrowhawk;andrelated
tradedressaretrademarksofO'ReillyMedia,Inc.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.


Preface
Wehadseveralgoalsinmindforthisbook.Manyofthemare
derivedfromthinkingaboutthatmythicalperfectMySQLbook
neitherofushadreadbutkeptlookingforonbookstore
shelves.Otherscomefromalotofexperiencehelpingother
usersputMySQLtoworkintheirenvironments.
Wewantedabookthatwasn'tjustaSQLprimer.Wewanteda
bookwithatitlethatdidn'tstartorendinsomearbitrarytime
frame("...inThirtyDays,""SevenDaysToaBetter...")and
didn'timplythatthereaderwasamoronofsomesortbecause
hewasreadingourbook.
Mostofallwewantedabookthatwouldhelpthereadertake
herMySQLskillstothenextlevel.Everybookwereadfocused
almostexclusivelyonSQLcommandsyntaxorcoveredMySQL
onlyataverybasiclevel.Nonereallyhelpedustounderstand
thedeeperissues.Wewantedabookthatwentdeeperand
focusedonreal-worldproblems.Howcanyousetupaclusterof
MySQLserverscapableofhandlingmillionsuponmillionsof
queriesandensurethatthingskeeprunningevenifacoupleof
theserversdie?
Wedecidedtowriteabookthatfocusednotjustontheneeds
oftheMySQLapplicationdeveloperbutalsoontherigorous
demandsoftheMySQLadministrator,whoneedstokeepthe
systemupandrunningnomatterwhathisprogrammersor
usersmaythrowattheserver.
Havingsaidthat,weassumethatyouarealreadyrelatively
experiencedwithMySQLand,ideally,havereadanintroductory
bookonMySQL.Inseveralchapters,we'llrefertocommonUnix
toolsformonitoringsystemperformance,suchastop,vmstat,
andsar.Ifyou'renotalreadyfamiliarwiththem(ortheir
equivalentonyouroperatingsystem),pleasetakeabitoftime


tolearnthebasics.Itwillserveyouwellwhenwelookat
systemperformanceandbottlenecks.


TheBasicLayoutofThisBook
Wefitalotofcomplicatedtopicsinthisbook.Herewe'llexplain
howweputthemtogetherinanorderthathopefullymakes
themeasyforyoutolearn.

BacktoBasics
Thefirsttwochaptersarededicatedtothebasicsthingsyou'll
needtobefamiliarwithbeforeyougettoadditional
configurationdetails.
Chapter1,reviewssomerudimentaryconfigurationbasics.This
bookassumesaprettygoodcommandoffoundationalMySQL
administration,butwe'llgooverthefundamentalsbrieflybefore
diggingdeeperintotheworldofMySQL.
Afterthat,Chapter2,coversthevariousstorageengines,or
tabletypes,thatarepartofMySQL.Thisisimportantbecause
storageengineselectionisoneofthefewthingsthatcanbe
nontrivialtochangeafteryoucreateatable.Wereviewthe
variousbenefits(andpotentialpitfalls)ofthevariousstorage
engines,andtrytoprovideenoughinformationtohelpyou
decidewhichengineisbestforyourparticularapplicationand
environment.

ThingstoReferenceasYouReadtheRestofthe
Book
Thenexttwochapterscoverthingsyou'llfindyourself
referencingtimeandagainthroughoutthecourseofthebook.


Chapter3,discussesthebasicsofbenchmarkingdetermining
whatsortofworkloadsyourservercanhandle,howfastitcan
performcertaintasks,andsoon.You'llwanttobenchmarkyour
applicationbothbeforeandafteramajorchange,soyoucan
judgehoweffectiveyourchangesare.Whatseemstobea
positivechangemayturnouttobeanegativeoneunderrealworldstress.[1]
[1]Managementfolksalsotendtolikemetricstheycanpointatandsay,"See,thisishowmuch
oursystemimprovedafterwespent$39.95onthatO'Reillybook!Wasn'tthatagreat
investment?"

InChapter4,wecoverthevariousnuancesofindexes.Manyof
thethingswediscussinlaterchaptershingeonhowwellyour
applicationputsMySQL'sindexestowork.Afirmunderstanding
ofindexesandhowtooptimizetheiruseissomethingyou'llfind
yourselfreturningtorepeatedlythroughouttheprocess.

PlacestoTuneYourApplication
ThenexttwochaptersdiscussareasinwhichtheMySQL
administrator,applicationdesigner,orMySQLprogrammercan
makechangestoimproveperformanceofaMySQLapplication.
InChapter5,wediscusshowtheMySQLprogrammermight
improvetheperformanceoftheMySQLqueriesthemselves.
Thisincludesbasics,suchashowthequeryparserwillparse
thequeriesprovided,aswellashowtooptimizequeriesfor
idealperformance.
Oncethequeriesareoptimized,thenextstepistomakesure
theserver'sconfigurationisoptimizedtoreturnthosequeriesin
thefastestpossiblemanner.InChapter6,wediscusssome
waystogetthemostoutofyourhardware,andtosuggest
hardwareconfigurationsthatmayprovidebetterperformance
forlarger-scaleapplications.


ScalingUpwardAfterMakingChanges
Onceyou'vegotaserverupandrunningasbestitcan,you
mayfindthatoneserversimplyisn'tenough.InChapter7,we
discussreplicationthatis,gettingyourdatacopiedautomatically
tomultipleservers.Whencombinedwiththeload-balancing
lessonsinChapter8,thiswillprovideyouwiththegroundwork
forscalingyourapplicationsinasignificantway.

MakeSureAllThatWorkIsn'tforNaught
Onceyouhaveconfiguredyourapplication,gottenitupand
running,andreplicatedyourdatabaseacrossmultipleservers,
yournexttaskasaMySQLadministratoristokeepitallgoing.
InChapter9,wediscussvariousbackupandrecovery
strategiesforyourMySQLdatabases.Thesestrategieshelp
minimizeyourdowntimeintheeventofinevitablehardware
failureandensuresthatyourdatasurvivessuchcatastrophes.
Finally,Chapter10,providesyouwithafirmgraspofsomeof
thesecurityissuesinvolvedinrunningaMySQLserver.More
importantly,weoffermanysuggestionstoallowyoutoprevent
outsidepartiesfromharmingtheserversyouhavespentallthis
timetryingtoconfigureandoptimize.

TheMiscellany
There'sacouplethingswedelveintothateitherdon't"fit"ina
particularchapterorarereferencedoftenenoughbymultiple
chaptersthattheydeserveabitofspecialattentionallto
themselves.


InAppendixA,wecovertheoutputoftheSHOWSTATUSand
SHOWINNODBSTATUScommands.Weattempttodecipherforthe
averageadministratorwhatallthosevariablesmeanandoffer
somewaystofindpotentialproblemsbasedontheirvalues
relativetoeachother.
AppendixB,coversaprogramcalledmytop,whichJeremy
wroteasaneasy-to-useinterfacetowhatyourMySQLserveris
presentlydoing.ItfunctionsmuchliketheUnixtopcommand
andcanbeinvaluableatallphasesofthetuningprocesstofind
whichMySQLthreadsareusingthemostresources.
Finally,inAppendixC,wediscussphpMyAdmin,aweb-based
toolforadministrationofaMySQLserver.phpMyAdmincan
simplifymanyoftheadministrator'sroutinejobsandallow
userstoissuequeriesagainstthedatabasewithouthavingto
buildaclientorhaveshellaccesstotheserver.


SoftwareVersionsandAvailability
WritingaMySQLbookhasproventobequiteachallenge.One
reasonisthatMySQLisamovingtarget.Inthetwo-plusyears
sinceJeremyfirstwrotetheoutlineforthisbook,numerous
releasesofMySQLhaveappeared.MySQL4.0wentfromtesting
tostable,andaswegotopress,MySQL4.1and5.0areboth
availableasalphaversions.Wehadtorevisetheoldertext
occasionallytoremovereferencestolimitationsthatwerefixed
afterthefact.[2]
[2]Notetobuddingauthors:writeasfastasyoucan.Thelongeryoudragitout,themorework
youhavetodo.

Wedidn'tuseasingleversionofMySQLforthisbook.Instead,
weusedahandfulofMySQL4.0and4.1releases,while
occasionallylookingbackathowthingsusedtobeinthe3.23
days.MySQL5.0isstillinsomuchfluxthatwesimplycould
notattempttocoveritinthefirstedition.Thesameistruefor
the(currently)newMySQLAdministratorGUItool.
Throughoutthisbook,weassumeabaselineversionofMySQL
4.0.14andhavemadeanefforttonotefeaturesorfunctionality
thatmaynotexistinolderreleasesorthatmayexistonlyin
the4.1series.However,thedefinitivereferenceformapping
featurestospecificversionsistheMySQLdocumentationitself.
Weexpectthatyou'llfindyourselfvisitingtheannotatedonline
documentation(http://www.mysql.com/doc/)fromtimetotime
asyoureadthisbook.
AnothergreataspectofMySQListhatitrunsonalloftoday's
popularplatforms:MacOSX,Windows,Linux,Solaris,
FreeBSD:younameit!However,ourexperienceisheavily
skewedtowardLinuxandFreeBSD.Whenpossible,we'vetried
tonotedifferencesWindowsusersarelikelytoencounter,which
tendtocomeintwoflavors.First,filepathsarecompletely


different.Chapter1containsnumerousreferencestoC:\mysql
andthelocationofconfigurationfilesonWindows.
PerlistheotherroughspotwhendealingwithMySQLon
Windows.MySQLcomeswithseveralusefulutilitiesthatare
writteninPerlandcertainchaptersinthisbookpresent
examplePerlscriptsthatformthebasisofmorecomplextools
you'llbuild.However,Windowsdoesn'tcomewithPerl.Inorder
tousethesescripts,you'llneedtodownloadaWindowsversion
ofPerlfromActiveStateandinstallthenecessaryadd-on
modules(DBIandDBD::mysql)forMySQLaccess.


ConventionsUsedinThisBook
Thefollowingtypographicalconventionsareusedinthisbook:

Plaintext
Indicatesmenutitles,menuoptions,menubuttons,and
keyboardaccelerators(suchasAltandCtrl).

Italic
Indicatesnewterms,exampleURLs,exampleemail
addresses,usernames,hostnames,filenames,file
extensions,pathnames,directories,andutilities.

Constantwidth
Indicateselementsofcode,configurationoptions,variables,
functions,modules,thecontentsoffiles,ortheoutputfrom
commands.

Constantwidthbold
Showscommandsorothertextthatshouldbetyped
literallybytheuser.

Constantwidthitalic


Showstextthatshouldbereplacedwithuser-supplied
values.


UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdon'tneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesn'trequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesn'trequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdon'trequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"HighPerformanceMySQL:Optimization,Backups,
Replication,andLoadBalancing,byJeremyD.Zawodnyand
DerekJ.Balling.Copyright2004O'ReillyMedia,Inc.,0-59600306-4."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat
permissions@oreilly.com.


HowtoContactUs
Pleaseaddresscommentsandquestionsconcerningthisbookto
thepublisher:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
(800)998-9938(intheUnitedStatesorCanada)
(707)829-0515(internationalorlocal)
(707)829-0104(fax)
Wehaveawebpageforthisbook,wherewelisterrata,
examples,andanyadditionalinformation.Youcanaccessthis
pageat:
http://www.oreilly.com/catalog/hpmysql/
Tocommentorasktechnicalquestionsaboutthisbook,send
emailto:
bookquestions@oreilly.com
Formoreinformationaboutourbooks,conferences,Resource
Centers,andtheO'ReillyNetwork,seeourwebsiteat:
http://www.oreilly.com
Theauthorsmaintainasitecalled:
http://highperformancemysql.com
ThereyouwillfindnewinformationonMySQLreleases,updates
tothetoolsshowninthebook,andpossiblyothergoodiessuch
asquestion-and-answerforums.Visitregularly!


Acknowledgments
Abooklikethisdoesn'tcomeintobeingwithouthelpfrom
literallydozensofpeople.Withouttheirassistance,thebook
youholdinyourhandswouldprobablystillbeabunchofsticky
notesonthesideofourmonitors.Thisisthepartofthebook
wherewegettosaywhateverwelikeaboutthefolkswho
helpedusout,andwedon'thavetoworryaboutmusicplaying
inthebackgroundtellingustoshutupandgoaway,asyou
mightseeonTVduringanawardsshow.
Wecouldn'thavecompletedthisprojectwithouttheconstant
prodding,begging,pleading,andsupportfromoureditor,Andy
Oram.[3]Ifthereisonepersonmostresponsibleforthebookin
yourhands,it'sAndy.Wereallydoappreciatetheweeklynag
sessions.
[3]Thenagain,ifthere'sasecondeditiononthehorizon,onemightarguethatthisprojectisnot
complete.

Andyisn'talone,though.AtO'Reillythereareabunchofother
folkswhohadsomepartingettingthosestickynotesconverted
toacohesivebookthatyou'dbewillingtoread,sowealso
havetothanktheproduction,illustration,andmarketingfolks
forhelpingtopullthisbooktogether.And,ofcourse,thanksto
TimO'Reillyforhiscontinuedcommitmenttoproducingsomeof
theindustry'sfinestdocumentationforpopularopensource
software.
Finally,we'dbothliketogiveabigthankstothefolkswho
agreedtolookoverthevariousdraftsofthebookandtellusall
thethingsweweredoingwrong:ourreviewers.Theyspentpart
oftheir2003holidaybreaklookingoverroughlyformatted
versionsofthistext,fulloftypos,misleadingstatements,and
outrightmathematicalerrors.Innoparticularorder,thanksto
Brian"Krow"Aker,Mark"JDBC"Matthews,Jeremy"theother


Jeremy"Cole,Mike"VBMySQL.com"Hillyer,Raymond
"Rainman"DeRoo,Jeffrey"RegexMaster"Friedl,Jason
DeHaan,DanNelson,Steve"UnixWiz"Friedl,andlastbutnot
least,Kasia"UnixGirl"Trapszo.

FromJeremy
IwouldagainliketothankAndyforagreeingtotakeonthis
projectandforcontinuallybeatingonusformorechapter
material.Derek'shelpwasessentialforgettingthelast20-30%
ofthebookcompletedsothatwewouldn'tmissyetanother
targetdate.Thanksforagreeingtocomeonboardlateinthe
processanddealwithmysporadicburstsofproductivity,and
forhandlingXMLgruntwork,Chapter10AppendixC,andall
theotherstuffIthrewyourway.
Ialsoneedtothankmyparentsforgettingmethatfirst
Commodore64computersomanyyearsago.Theynotonly
toleratedthefirst10yearsofwhatseemstobealife-long
obsessionwithelectronicsandcomputertechnology,butquickly
becamesupportersofmynever-endingquesttolearnanddo
more.
NextI'dliketothankagroupofpeopleI'vehadthedistinct
pleasureofworkingwithwhilespreadingMySQLreligionat
Yahooduringthelastfewyears.JeffreyFriedlandRay
Goldbergerprovidedencouragementandfeedbackfromthe
earlieststagesofthisundertaking.Alongwiththem,Steve
Morris,JamesHarvey,andSergeyKolychevputupwithmy
seeminglyconstantexperimentationontheYahoo!Finance
MySQLservers,evenwhenitinterruptedtheirimportantwork.
ThanksalsotothecountlessotherYahooswhohavehelpedme
findinterestingMySQLproblemsandsolutions.And,most
importantly,thanksforhavingthetrustandfaithinmeneeded
toputMySQLintosomeofthemostimportantandvisibleparts
ofYahoo'sbusiness.


AdamGoodman,thepublisherandownerofLinuxMagazine,
helpedmeeaseintotheworldofwritingforatechnical
audiencebypublishingmyfirstfeature-lengthMySQLarticles
backin2001.Sincethen,he'staughtmemorethanherealizes
abouteditingandpublishingandhasencouragedmeto
continueonthisroadwithmyownmonthlycolumninthe
magazine.Thanks,Adam.
ThankstoMontyandDavidforsharingMySQLwiththeworld.
SpeakingofMySQLAB,thankstoalltheothergreatfolksthere
whohaveencouragedmeinwritingthis:Kerry,Larry,Joe,
Marten,Brian,Paul,Jeremy,Mark,Harrison,Matt,andtherest
oftheteamthere.Youguysrock.
Finally,thankstoallmyweblogreadersforencouragingmeto
writeinformallyaboutMySQLandothertechnicaltopicsona
dailybasis.And,lastbutnotleast,thankstotheGoonSquad.

FromDerek
LikeJeremy,I'vegottothankmyfamily,formuchthesame
reasons.Iwanttothankmyparentsfortheirconstantgoading
thatIshouldwriteabook,evenifthisisn'tanywherenearwhat
theyhadinmind.Mygrandparentshelpedmelearntwo
valuablelessons,themeaningofthedollarandhowmuchI
wouldfallinlovewithcomputers,assheloanedmethemoney
tobuymyfirstCommodoreVIC-20.
Ican'tthankJeremyenoughforinvitingmetojoinhimonthe
whirlwindbook-writingrollercoaster.It'sbeenagreat
experienceandIlookforwardtoworkingwithhimagaininthe
future.
AspecialthanksgoesouttoRaymondDeRoo,Brian
Wohlgemuth,DavidCalafrancesco,TeraDoty,JayRubin,Bill
Catlan,AnthonyHowe,MarkO'Neal,GeorgeMontgomery,


GeorgeBarber,andthemyriadotherpeoplewhopatiently
listenedtomegripeaboutthings,letmebounceideasoffthem
toseewhetheranoutsidercouldunderstandwhatIwastrying
tosay,orjustmanagedtobringasmiletomyfacewhenI
neededitmost.Withoutyou,thisbookmightstillhavebeen
written,butIalmostcertainlywouldhavegonecrazyinthe
process.


Chapter1.BackToBasics
ManyMySQLusersandadministratorsslideintousingMySQL.
Theyhearitsbenefits,findthatit'seasytoinstallontheir
systems(orbetteryet,comespre-installed),andreadaquick
bookonhowtoattachsimpleSQLoperationstowebsitesor
otherapplications.
Itmaytakeseveralmonthsforthedragonstoraisetheirheads.
Perhapsoneparticularwebpageseemstotakeforever,ora
systemfailurecorruptsadatabaseandmakesrecoverydifficult.
Real-lifeuseofMySQLrequiresforethoughtandcareandalittle
benchmarkingandtesting.ThisbookisfortheMySQL
administratorwhohasthebasicsdownbutrealizestheneedto
gofurther.It'sagoodbooktoreadafteryou'veinstalledand
learnedhowtouseMySQLbutbeforeyoursitestartstogeta
lotoftraffic,andthedragonsarebreathingdownyourneck.
(Whenproblemsoccurduringacriticalservice,yourfellow
workersandfriendlymanagerstarttotakeondecidedly
dragon-likeappearances.)
Thetechniquesweteacharevaluableinmanydifferent
situations,andsometimestosolvedifferentproblems.
Replication,forinstance,maybeamatterofreliabilityfor
youanessentialguaranteethatyoursitewillstillbeupifoneor
twosystemsfail.Butreplicationcanalsoimproveperformance;
weshowyouarchitecturesandtechniquesthatsolvemultiple
problems.
Wealsotakeoptimizationfarbeyondthesimpleuseofindexes
anddiagnostic(EXPLAIN)statements:thisbooktellsyouwhat
thefactorsingoodperformanceare,wherebottlenecksoccur,
howtobenchmarkMySQL,andotheradvancedperformance
topics.


Weaskforalittlemorepatienceandtimecommitmentthanthe
averageintroductorycomputerbook.Ourapproachinvolvesa
learningcycle,andexperienceconvincesusthatit'sultimately
thefastestandmostefficientwaytogetwhereyouwant.
Afterdescribingtheproblemswe'retryingtosolveinagiven
chapter,westartwithsomebackgroundexplanation.Inother
words,wegiveyouamentalmodelforunderstandingwhat
MySQLisdoing.Thenwedescribetheoptionsyouhavetosolve
theproblem,andonlyafterallthatdowedescribeparticular
toolsandtechniques.
Thisbookisclearlynottheendofthelineintermsof
information.Knowingthat,we'vestartedawebsite,
http://www.highperformancemysql.com,whereweputuseful
scriptsandnewtopics.SeethePrefaceformoreinformation.
BeforewedigintohowtotuneyourMySQLsystemtooptimum
performance,it'sbestifwegooveracoupleofgroundrules
andmakesureeveryoneisonthesamepage.


1.1BinaryVersusCompiled-From-Source
Installations
TherearetwowaysyoucaninstallMySQL.Asanovice
administrator,youmayhavesimplyinstalledabinarypackage
thathadprecompiledexecutables,libraries,andconfiguration
files,andplacedthosefileswhereverthemakerofthebinary
packagedecidedtheyshouldgo.

It'sexceedinglyrareforaWindowsusertocompilehisowncopyof
MySQL.Ifyou'rerunningMySQLonWindows,feelfreetodownload
yourcopyfromtheMySQLwebsiteandskipthisdiscussion.

Alternatively,foranynumberofreasons,youmighthave
decidedtocompiletheMySQLbinariesonyourown,by
downloadingasourcetarballandconfiguringtheinstallationto
bestmeetyourneeds.However,don'tdosolightly.Compiling
fromsourcehasledtocountlesshoursofpainforsomeusers,
mostlyduetosubtlebugsintheircompilersorthreadlibraries.
Forthisveryreason,thestandardbinariesprovidedbyMySQL
ABarestaticallylinked.Thatmeanstheyareimmunetoany
bugsinyourlocallyinstalledlibraries.
Therearen'ttoomanyplaceswheretheissueof"binaryversus
compiled-from-source"willcomeintoplayintheaverage
MySQLtuningregimen,buttheydohappen.Forexample,in
Chapter10,ouradviceonchrootingyourinstallationcanbe
usedonlyifeveryfileMySQLneedsisbroughtintoasingle
directorytree,whichmightnotbethecaseinabinary
installation.
Foranoviceadministratoronasimpleinstallation,we


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×