You are on page 1of 23

MySQL Administration How-To

Authors: Creation ate:

Trifon M. Anguelov Susarla Chakravarthy Se!tem"er #$% &##' Se!tem"er )*% &##' ).#

Last (!date date: +ersion:

MySQL Administration How-To

Contents
1. General Information ................................................................... 2 1.1 1.2 1.3 1.4 1.5 1.6 1. Internals and Portability .............................................................. Security ....................................................................................... Scalability and Limits .................................................................. Connectivity ................................................................................ Localization ................................................................................. Clients and Tools ......................................................................... Com!arison o" #yS$L %it& Post'reS$L ...................................... 2 2 3 3 3 4 4

2. Installation and configuration of MySQL ............................... 2.1 2.2 2.3 2.4 2.5 Installation o" #yS$L on (ree)S* mac&ines .............................. #yS$L data"iles location.............................................................. #yS$L t&reads and database connection ................................... 13 #yS$L con"i'uration ................................................................... 16 #yS$L database structure + database "ile ty!es ........................ 2,

3. Security ......................................................................................... )ac-u! and .ecovery ......................................................................... Corru!tion .......................................................................................... Tunin' ................................................................................................

MySQL Administration How-To

& 1. MySQL General Information


The Main ,eatures of MySQL data"ase are:

1.1 Internals and Portability - -ritten in C and C... - (ses /0( Automake 1).'2% Auto3onf 1+ersion &.*& or newer2% and Li"tool for !orta"ility. - -orks on many different !latforms4 A56s for C% C..% 7iffel% 8ava% 5erl% 5H5% 5ython% 9u"y% and T3l. - ,ully multi-threaded using kernel threads% this means it 3an easily use multi!le C5(s if availa"le. - +ery fast :-tree disk ta"les with inde; 3om!ression and thread-"ased memory allo3ation system. - +ery fast <oins using an o!timi=ed one-swee! multi-<oin% 3an mi; ta"les from different data"ases in the same >uery. - 6n-memory hash ta"les whi3h are used as tem!orary ta"les. - SQL fun3tions are im!lemented through a highly o!timi=ed 3lass li"rary and should "e as fast as !ossi"le - (sually there isn?t any memory allo3ation at all after >uery initiali=ation.

1.2 Security - All !assword traffi3 is en3ry!ted 3onne3ting to a server. - A !rivilege and !assword system that is very fle;i"le and allows host-"ased verifi3ation.

1.3 Scalability and Limits - Handles large data"ases. Ma;imum si=e for a ta"le is @T: 1default '/:2.

MySQL Administration How-To

A - (! to A& inde;es !er ta"le. 7a3h inde; may 3onsist of ) to )$ 3olumns or !arts of 3olumns. - The ma;imum inde; width is *## "ytes 1this may "e 3hanged when 3om!iling MySQL Server2. - An inde; may use a !refi; of a CHA9 or +A9CHA9 field.

1.4 Connectivity - Clients may 3onne3t to the MySQL server using TC5B65 So3kets% (ni; So3kets 1(ni;2% or 0amed 5i!es 10T2. - All C :C &.* fun3tions and many others.

1.

Locali!ation

- All 3om!arisons for normal string 3olumns are 3ase-insensitive. - The server 3an !rovide error messages to 3lients in many languages. - MySQL Server su!!orts many different 3hara3ter sets that 3an "e s!e3ified at 3om!ile and runtime.

1." Clients and #ools - 6n3ludes myisam3hk% a very fast utility for ta"le 3he3king% o!timi=ation% and re!air. - All of the fun3tionality of myisam3hk is also availa"le through the SQL interfa3e as well. - All MySQL !rograms 3an "e invoked with the --hel! or -D o!tions to o"tain on-line assistan3e.

MySQL Administration How-To

' 1.$ Com%arison of MySQL and Post&reSQL MySQL Server offers the following advantages over 5ostgreSQL: - MySQL Server is generally mu3h faster than 5ostgreSQL - MySQL '.#.) also has a >uery 3a3he that 3an "oost u! the >uery s!eed for mostlyread-only sites many times. - MySQL Server is used more in !rodu3tion environments than 5ostgreSQL - MySQL has more A56s to other languages and is su!!orted "y more e;isting !rograms than 5ostgreSQL. - MySQL Server works on &'BE heavy-duty systems. 6n most 3ir3umstan3es you never have to run any 3leanu!s on MySQL Server. 5ostgreSQL doesn?t yet su!!ort &'BE systems "e3ause you have to run +AC((M on3e in a while to re3laim s!a3e from (5 AT7 and 7L7T7 3ommands and to !erform statisti3s analyses that are 3riti3al to get good !erforman3e with 5ostgreSQL. +AC((M is also needed after adding a lot of new rows to a ta"le. Cn a "usy system with lots of 3hanges% +AC((M must "e run very fre>uently% in the worst 3ases even many times a day. uring the +AC((M run% whi3h may take hours if the data"ase is "ig% the data"ase is% from a !rodu3tion stand!oint% !ra3ti3ally dead. - MySQL Server su!!orts more of the standard C :C fun3tions than 5ostgreSQL. - M79/7 ta"les gives a uni>ue way to instantly make a view over a set of identi3al ta"les and use these as one. This is !erfe3t for systems where you have log files that you order% for e;am!le% "y month. - The o!tion to 3om!ress read-only ta"les% "ut still have dire3t a33ess to the rows in the ta"le% gives "etter !erforman3e "y minimi=ing disk reads. This is very useful when you are ar3hiving things. - MySQL Server is 3oded from the start to "e multi-threaded% while 5ostgreSQL uses !ro3esses. - Conte;t swit3hing and a33ess to 3ommon storage areas is mu3h faster "etween threads than "etween se!arate !ro3esses. This gives MySQL Server a "ig s!eed advantage in multi-user a!!li3ations and also makes it easier for MySQL Server to take full advantage of symmetri3 multi!ro3essor 1SM52 systems. - MySQL Server has a mu3h more so!histi3ated !rivilege system than 5ostgreSQL. -hile 5ostgreSQL only su!!orts 60S79T% S7L7CT% and (5 AT7B 7L7T7 grants !er user on a data"ase or a ta"le% MySQL Server allows you to define a full set of different !rivileges on the data"ase% ta"le% and 3olumn level.

MySQL Administration How-To

* - MySQL Server also allows you to s!e3ify the !rivilege on host and user 3om"inations. - MySQL Server su!!orts a 3om!ressed 3lientBserver !roto3ol whi3h im!roves !erforman3e over slow links - All MySQL ta"le ty!es 1e;3e!t 6nno :2 are im!lemented as files 1one ta"le !er file2% whi3h makes it really easy to "a3k u!% move% delete% and even symlink data"ases and ta"les% even when the server is down. - Tools to re!air and o!timise My6SAM ta"les 1the most 3ommon MySQL ta"le ty!e2. A re!air tool is only needed when a !hysi3al 3orru!tion of a datafile ha!!ens% usually from a hardware failure. 6t allows a ma<ority of the data to "e re3overed. - (!grading MySQL Server is !ainless. - Fou don?t need to dum!Brestore your data% as you have to do with most 5ostgreSQL u!grades.

raw"a3ks with MySQL Server 3om!ared to 5ostgreSQL: - The transa3tion su!!ort in MySQL Server is not yet as well tested as 5ostgreSQL?s system. - :e3ause MySQL Server uses threads% whi3h are not yet flawless on many CSs% one must either use "inaries or 3arefully follow our instru3tions to get an o!timal "inary that works in all 3ases. - (!dates that run over multi!le ta"les are harder to do in MySQL Server. This will% however% "e fi;ed in MySQL Server '.#.& with multi-ta"le (5 AT7 and in MySQL Server '.) with su"sele3ts. - 6n MySQL Server '.# one 3an use multi-ta"le deletes to delete from many ta"les at the same time.

MySQL Administration How-To

$ Currently su!!orted featured in MySQL Server:

,eatures Su" sele3ts ,oreign keys +iews Stored !ro3edures Triggers (nions ,ull <oin Constraints Cursors 9-trees 6nherited ta"les 7;tensi"le ty!e system

MySQL version '.) '.) 1A.&A with 6nno :2 *.# *.# *.# '.# '.) '.) or *.# '.) or *.# '.) 1for My6SAM ta"les2 0ot !lanned 0ot !lanned

MySQL Administration How-To

2. Installation and confi&uration of MySQL


2.1 Installation of MySQL on 'ree(S) mac*ines MySQL server and 3lient GyinstH !a3kages are availa"le at: htt!:BBdist.3or!.yahoo.3omB"y-3ategoryBmys>lBmys>lIserver htt!:BBdist.3or!.yahoo.3omB"y-3ategoryBmys>lBmys>lI3lient

:efore installing the mys>lIserver or mys>lI3lient !a3kages% 3he3k their de!enden3ies from the Gde!enden3ies gra!hH. To install on a lo3al ma3hine use these 3ommands 1as GrootH user2: J yinst install mys>lIserver J yinst install mys>lI3lient This will !i3k u! the 3urrent sta"le version of these !rodu3ts. 6f you need to install older version% go the a"ove (9Ls and use the e;a3t mys>lIserver or mys>lI3lient verisons. 7;am!le 1as GrootH user2: J yinst install mys>lIserver-'.#.)AIA J yinst install mys>lI3lient-A.&A.*) The GyinstH installation 3ommand will 3reate the MySQL installation and data"ase dire3tories% install the MySQL Gmys>lH 3onfiguration data"ase% install the MySQL GtestH test data"ase and 3reate the Bet3Bmy.3nf 1MySQL 3onfiguration2 file. :y default% the Gmys>lH data"ase has no se3urity enfor3ed and there is no !assword for MySQL GrootH user.

2.2 MySQL datafiles location +binary files, confi&uration files, lo& files, data files:y default the yinst installs the MySQL data"ase "inaries into BhomeByB"inB :

MySQL Administration How-To

@ J 3d BhomeByB"inB J ls -la mys>lK -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; & & & & & & & & & & & & & & & & & & & & & & & & & root root root root root root root root root root root root root root root root root root root root root root root root root wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel wheel )@$*#$ Mar &$ &##A mys>l A*E' Mar &$ &##A mys>lI3onfig &L@# Aug ' &##A mys>lI3onvertIta"leIformat )#'&& Aug ' &##A mys>lIe;!lainIlog &$*E Aug ' &##A mys>lIfindIrows '@$ Aug ' &##A mys>lIfi;Ie;tensions $LAA Aug ' &##A mys>lIfi;I!rivilegeIta"les &A$)A@ Aug ' &##A mys>lIftIdum! )A$L$' Aug ' &##A mys>lIinstall )')$' Aug ' &##A mys>lIinstallId" $)@$ Aug ' &##A mys>lIse3ureIinstallation )E&E@ Aug ' &##A mys>lIset!ermission )A$*# Aug ' &##A mys>lIta"leinfo A)&$ Aug ' &##A mys>lI=a! )))*&# Mar &$ &##A mys>la33ess &@)E# Mar &$ &##A mys>ladmin *'#AL Aug ' &##A mys>l"inlog )#A@) Aug ' &##A mys>l"ug &)$#) Mar &$ &##A mys>l3he3k )@L&* Aug ' &##A mys>ldImulti )#'*@ Aug ' &##A mys>ldIsafe A$*L) Mar &$ &##A mys>ldum! 'L@L Aug ' &##A mys>ldum!slow A)&&) Aug ' &##A mys>lhot3o!y )EA#L Mar &$ &##A mys>lim!ort

Fou should have this !ath added to your user a33ount ."ashI!rofile on the MySQL data"ase server or you 3an do that on the fly: M e;!ort 5ATHNM5ATH:BhomeByB"in MySQL 3onfiguration files sear3h order is first in the user?s home dire3tory and then to the Bet3B dire3tory. This allow ea3h user to have it?s own my.3nf file in it?s own home dire3tory and1or2 one glo"al Bet3Bmy.3nf file. Fahoo?s yinst Gmys>lIserverH installation !la3es the glo"al 3onfiguration file into Bet3Bmy.3nf file% "ut you 3an also see this file as a soft link to BhomeByBet3Bmy.3nf file: M ls -la Bet3Bmy.3nf lrw;r-;r-; ) root wheel )@ Mar ' &##' Bet3Bmy.3nf -O BhomeByBet3Bmy.3nf

MySQL Administration How-To

L MySQL data"ase server 3onfiguration file 1my.3nf2 has the data"ase !arameters as: "asedir datadir log-error tm!dir !id-file - MySQL installation root dire3tory - MySQL datafiles dire3tory - MySQL error log dire3tory - MySQL tem!orary dire3tory - MySQL data"ase server 5ro3ess 6

file

MySQL data"ase server?s memory and 3onfiguration !arameters are setu! as: set-varia"le N Pvaria"leInameONPvaria"leIvalueO Fou 3an use GJH to !ut 3omments into the 3onfiguration file. :lank s!a3es are not enfor3ed% so you 3an format the entries with as many "lank s!a3es as you wish. All the !arameters are 3ase sensitive. 7;am!le of the my.3nf file is: !ort N AA#$ so3ket N Btm!Bmys>l.so3k user N mys>l ski!-lo3king set-varia"le N keyI"ufferNA&M set-varia"le N ma;IallowedI!a3ketN@M set-varia"le N ta"leI3a3heN&*$ set-varia"le N sortI"ufferN*)&Q set-varia"le N netI"ufferIlengthN@Q set-varia"le N myisamIsortI"ufferIsi=eN)$M set-varia"le N ma;I3onne3tIerrorsNLLLLLLLLL set-varia"le N ma;I3onne3tionsN&## "asedir N BhomeBy datadir N BhomeByBvarBmys>lBdata log-error N BhomeByBlogsBmys>lBmys>ld.err tm!dir N Btm!B !id-file N BhomeByBvarBmys>lBmys>ld.!id JJ avoid ,ree:S ski!-name-resolve 0S !ro"lems

JJ (n3omment these if this server will "e a master. log-"in server-id N)

JJ 6nno : settings innod"IdataIhomeIdir N Bd)BvarBmys>lBi"data innod"IdataIfileI!ath N i"data):&*$M:autoe;tend

MySQL Administration How-To

)# innod"IlogIgrou!IhomeIdir N BhomeByBvarBmys>lBi"log innod"IlogIar3hIdir N BhomeByBvarBmys>lBi"log set-varia"le N innod"I"ufferI!oolIsi=eN)&@M set-varia"le N innod"IadditionalImemI!oolIsi=eN&M set-varia"le N innod"IlogIfileIsi=eN$'M set-varia"le N innod"IlogI"ufferIsi=eN@M innod"IflushIlogIatItr;I3ommitN) set-varia"le N innod"Ilo3kIwaitItimeoutNA## JJ Query 3a3he >ueryI3a3heIsi=e N )$M >ueryI3a3heIty!e N ) Rmyisam3hkS set-varia"le set-varia"le set-varia"le set-varia"le N N N N keyI"ufferN&#M sortI"ufferN&#M readI"ufferN&M writeI"ufferN&M

MySQL data"ase server has two default log files lo3ated into the BhomeByBlogsBmys>lB dire3tory: J ls -la BhomeByBlogsBmys>lB -rw-r--r-- ) root users *A$ 8un E )A:*$ mys>l.log -rw-rw---- ) mys>l users * Se! L #E:A# mys>ld.err 6n mys>l.log file are re3orded all the MySQL data"ase startu! and shutdown events: Starting mys>ld daemon with data"ases from BhomeByBvarBmys>lBdata #A)&)L )#:#A:&' mys>ld ended Starting mys>ld daemon with data"ases from BhomeByBvarBmys>lBdata Qilling mys>ld with !id &L* -ait for mys>ld to e;itT3 #A)&)L )#:#E:#' mys>ld ended done Starting mys>ld daemon with data"ases from BhomeByBvarBmys>lBdata Qilling mys>ld with !id &L) -ait for mys>ld to e;itT3 #A)&)L )':&@:#' mys>ld ended

6n mys>ld.err file are re3orded all the MySQL data"ase server error messages at startu!% shutdown% re!li3ation errors% 3ore dum!s% et3:

MySQL Administration How-To

)) 6nno :: 7rror: Mem area si=e is #. 5ossi"ly a memory overrun of the 6nno :: !revious allo3ated areaU 6nno :: A!!arent memory 3orru!tion: mem dum! len *##4 he; EE)A"@######f$AdEE*f"A#EL*&dA#E#$AE*E&&e$A##)3#######)######)#EdEE)A) #EdEE)A################a@######################a@######'############ ###$L$'AdA*$#L'*L#L*)e*d$#e$L$'AdA)A@AEA)A'#A#######A############### ########A##############@#AA##&f##&"##&L##&)##)a##)'##)##)######@A''*) 4 as3 w......NwI...-#!3ur.3..........Vw..V................................ dN*W.F.Q...idN)@E)'.........................A.B...2.U........... Q............:..".W..w................:... Xd!............................)AA'*&.)E@$)E.dailyI"IdataI3am!aignIadsI&.............NwI.h. w#sel.3.....................................Y...Y...........)A.)@.&'.&E.$')'#@.*.................................. ....................................................................................................................4 6nno :: S3anning "a3kward trying to find !revious allo3ated mem "lo3ks Mem "lo3k at - &'#% file #!3ur.3% line &@ 6nno :: S3anning forward trying to find ne;t allo3ated mem "lo3ks

#'#@&@ $:##:## 7rror reading !a3ket from server: Lost 3onne3tion to MySQL server during >uery 1serverIerrnoN&#)A2 #'#@&@ $:##:## Slave 6BC thread: ,ailed reading log event% re3onne3ting to retry% log ?mdr)-"in.)$E? !osition )#)#LL$@ #'#@&@ $:##:#L 7rror reading !a3ket from server: Lost 3onne3tion to MySQL server during >uery 1serverIerrnoN&#)A2 #'#@&@ $:##:#L Slave 6BC thread: ,ailed reading log event% re3onne3ting to retry% log ?mdr)-"in.)$L? !osition ' #'#@&L $:##:## 7rror reading !a3ket from server: error reading log entry 1serverIerrnoN)&A$2 #'#@&L $:##:## /ot fatal error )&A$: ?error reading log entry? from master when reading data from "inary log #'#@&L $:##:## Slave 6BC thread e;iting% read u! to log ?mdr)-"in.)E#?% !osition ' #'#@&L &&:*':)L Slave 6BC thread: 3onne3ted to master ?re!lYmdr).data.yahoo.3om:AA#$?% re!li3ation started in log ?mdr)-"in.)E#? at !osition ' #'#L#) )):&&:&E Slave 6BC thread e;iting% read u! to log ?mdr)-"in.)E@?% !osition ' #'#L#) )):&&:A& Slave 6BC thread: 3onne3ted to master ?re!lYmdr).data.yahoo.3om:AA#$?% re!li3ation started in log ?mdr)-"in.)E@? at !osition ' #'#L#) )A:#&:A# Slave: re3eived # length !a3ket from server% a!!arent master shutdown: #'#L#) )A:#&:A# Slave 6BC thread: ,ailed reading log event% re3onne3ting to retry% log ?mdr)-"in.)EL? !osition ' #'#L#) )A:#&:A# Slave 6BC thread: error re3onne3ting to master ?re!lYmdr).data.yahoo.3om:AA#$?: 7rror: ?Lost 3onne3tion to MySQL server during >uery? errno: &#)A retry-time: $# retries: @$'## 799C9: ))'$ Ta"le ?M 9.M 9I ataSet? doesn?t e;ist #'#L#) )A:#E:)E Slave: 7rror ?Ta"le ?M 9.M 9I ataSet? doesn?t e;ist? on >uery

MySQL Administration How-To

)& ?u!date M 9I ataSet set validto N ?&##'-#L-#) )A:#$:*'? where 1oid N )#L@A*' and validfrom PN ?&##'-#L-#) )A:#$:*'? and validto N ?LLLL-)&-A) &A:*L:*L?2? 1default data"ase was ?M 9?2% errorI3odeN))'$ #'#L#) )A:#E:)E 7rror running >uery% slave SQL thread a"orted. ,i; the !ro"lem% and restart the slave SQL thread with ZSLA+7 STA9TZ. -e sto!!ed at log ?mdr)"in.)@)? !osition )*#@' #'#L#) )A:)#:)# Slave 6BC thread e;iting% read u! to log ?mdr)-"in.)@)?% !osition ')A*@ #'#L#) )A:)A:*# Slave 6BC thread: 3onne3ted to master ?re!lYmdr).data.yahoo.3om:AA#$?% re!li3ation started in log ?mdr)-"in.)@)? at !osition ' (sually% ea3h line in the mys>ld.err file is started with the date formated as GFFMM H and the time stam! formated as GHH&':M6:SSH

The main MySQL data"ase files dire3tory is BhomeByBvarBmys>l . 6n this dire3tory are stored the My6SAM and 6nno : data"ase files: M ls -la BhomeByBvarBmys>l total $ drw;rw;r-; * mys>l users *)& Aug &' )):## . drw;r-;r-; @ root wheel *)& 8un E )):** .. drw;rw;r-; * mys>l users *)& Se! ) )A:)A data drw;rw;r-; & mys>l users *)& 8un E )):** i"data drw;rw;r-; & mys>l users *)& 8un E )):** i"log

The My6SAM datafiles are stored in the BhomeByBvarBmys>lBdata dire3tory. 7a3h MySQL data"ase has su"-dire3tory into this dire3tory. ,or instan3e in the following e;am!le there are three su"-dire3tories for three different MySQL data"ases [ M 9% mys>l and test: M ls -la BhomeByBvarBmys>lBdata total '$&&@) drw;rw;r-; * mys>l users *)& Se! ) )A:)A . drw;rw;r-; * mys>l users *)& Aug &' )):## .. drw;------ & mys>l users *)& Se! ) )A:)) M 9 drw;------ & mys>l users *)& 8un E )):** mys>l drw;------ & mys>l users *)& Aug )& #@:)A test :y default two MySQL data"ases Gmys>lH and GtestH are 3reated "y the yinst.

MySQL Administration How-To

)A Two im!ortant disk-"ased resour3es managed "y the 6nno : storage engine are its ta"les!a3e data files and its log files. 6nno : ata : BhomeByBvarBmys>lBi"data

J ls -la BhomeByBvarBmys>lBi"data -rw-rw---- ) mys>l users E@@*&L)*& Se! )A )$:'@ i"data) 6nno : Logs : BhomeByBvarBmys>lBi"log J ls -la BhomeByBvarBmys>lBi"logB -rw-rw---- ) mys>l users $E)#@@$' Se! )A )$:'L i"Ilogfile# -rw-rw---- ) mys>l users $E)#@@$' Se! )) )E:AL i"Ilogfile)

2.3 MySQL t*reads and database connection MySQL data"ase server is running as se!arate thread !ro3essed started "y the MySQL start !rogram [ mys>ldIsafe: M !s -au;w \ gre! mys>ldIsafe root A@@&' #.# #.) $*$ )@@ !E 6 )):*EAM #:##.#) B"inBsh B homeByB"inBmys>ldIsafe --datadirNBhomeByBvarBmys>lBdata [!id-file

The mys>ldIsafe starts the MySQL thread !ro3esses: M !s au;w \ gre! mys>ld \ gre! -v mys>ldIsafe \ 3ut -d Z-Z -f) mys>l A@@*L #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.)* B homeByBli"e;e3Bmys>ld mys>l A@@$# #.# ).) )))EE$ &L&# !E S )):*EAM #:##.#L B homeByBli"e;e3Bmys>ld mys>l A@@$) #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.## B homeByBli"e;e3Bmys>ld mys>l A@@$& #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.## B homeByBli"e;e3Bmys>ld mys>l A@@$A #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.#) B homeByBli"e;e3Bmys>ld mys>l A@@$' #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.## B homeByBli"e;e3Bmys>ld mys>l A@@$* #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.## B homeByBli"e;e3Bmys>ld mys>l A@@$$ #.# ).) )))EE$ &L&# !E S )):*EAM #:#&.AL B homeByBli"e;e3Bmys>ld mys>l A@@$E #.# ).) )))EE$ &L&# !E 6 )):*EAM #:##.## B

MySQL Administration How-To

)' homeByBli"e;e3Bmys>ld mys>l A@@$@ #.# ).) )))EE$ &L&# !E 6 homeByBli"e;e3Bmys>ld )):*EAM #:##.## B

To test the MySQL data"ase 3onne3tion% you have to have a valid a33ount and know its !assword. The 3onne3t strinng 3ould in3lude the MySQL data"ase you want to 3onne3t to: mys>l -u root mys>l 9eading ta"le information for 3om!letion of ta"le and 3olumn names Fou 3an turn off this feature to get a >ui3ker startu! with -A -el3ome to the MySQL monitor. Commands end with 4 or Tg. Four MySQL 3onne3tion id is L to server version: '.#.)E-Fahoo-SM5 Ty!e ?hel!4? or ?Th? for hel!. Ty!e ?T3? to 3lear the "uffer. mys>lO show ta"les4 .------------------------. \ Ta"lesIinImys>l \ .------------------------. \ 3olumnsI!riv \ \ d" \ \ fun3 \ \ host \ \ ta"lesI!riv \ \ user \ .------------------------. $ rows in set 1#.## se32 6n the a"ove e;am!le we 3onne3ted to MySQL data"ase 3alled Gmys>lH as user GrootH and >uery the ta"les in this data"ase. -e 3an also use the Gmys>lH 3lient to 3onne3t to the mys>ld and then 3onne3t to a !arti3ular MySQL data"ase or on3e 3onne3ted swit3h data"ases: mys>l -u root -el3ome to the MySQL monitor. Commands end with 4 or Tg. Four MySQL 3onne3tion id is )# to server version: '.#.)E-Fahoo-SM5 Ty!e ?hel!4? or ?Th? for hel!. Ty!e ?T3? to 3lear the "uffer. mys>lO show ta"les4 799C9 )#'$: 0o ata"ase Sele3ted

MySQL Administration How-To

)* Sin3e we didn?t s!e3ify a MySQL on 3onne3t time% we are getting an error when trying to >uery the data"ase ta"les. To 3onne3t to a data"ase: mys>lO show data"ases4 .--------------. \ ata"ase \ .--------------. \ mys>l \ \ test \ .--------------. & rows in set 1#.## se32 mys>lO 3onne3t mys>l4 9eading ta"le information for 3om!letion of ta"le and 3olumn names Fou 3an turn off this feature to get a >ui3ker startu! with -A Conne3tion id: )) Current data"ase: mys>l mys>lO show ta"les4 .------------------------. \ Ta"lesIinImys>l \ .------------------------. \ 3olumnsI!riv \ \ d" \ \ fun3 \ \ host \ \ ta"lesI!riv \ \ user \ .------------------------. $ rows in set 1#.## se32

And we 3an 3hange the data"ase we are 3onne3ted to: mys>lO 3onne3t test4 9eading ta"le information for 3om!letion of ta"le and 3olumn names Fou 3an turn off this feature to get a >ui3ker startu! with -A Conne3tion id: )& Current data"ase: test

MySQL Administration How-To

)$ mys>lO show ta"les4 .-----------------------------. \ Ta"lesIinItest \ .-----------------------------. \ TS570 975C9TI) \ .-----------------------------. ) row in set 1#.## se32

2.4 MySQL Confi&uration Sin3e the MySQL data"ase server in FahooU 6s installed via yinst !a3kage% there si a little 3ontrol over how the !a3kage was "uild% unless you "uild the MySQL !a3kage with your 3ustom 3onfigure o!tions. Some of the im!ortant 3onfigure o!tions are: The installation !refi; s!e3ifies where MySQL root dire3tory is: -!refi;NBhomeByB"in To "e a"le to load data from any outside files into mys>l data"ase: --ena"le-lo3al-infile MySQL default user name: --with-mys>ld-userNmys>l Fou 3an review the MySQL data"ase server "uild o!tions in the B homeByBshareBmys>lBmys>l-PversionO.s!e3 file. PtrifonYwineOBhomeByBshareBmys>l M -r-;r-;r-; & root wheel &'*)) 0ov )' &##A mys>l-'.#.)E.s!e3

,or the mys>l-'.#.)E.s!e3 file the o!tions are in this se3tion:

:uildMySQL12 X J The --ena"le-assem"ler sim!ly does nothing on systems that does not J su!!ort assem"ler s!eedu!s. sh -3 Z5ATHNTZMXMFSQLI:(6L I5ATH:-M5ATHVTZ T CCNTZMXCC:-MMFSQLI:(6L ICCVTZ T

MySQL Administration How-To

)E C]]NTZMXC]]:-MMFSQLI:(6L IC]]VTZ T C,LA/SNTZMXMFSQLI:(6L IC,LA/S:-M95MIC5TI,LA/SVTZ T C]],LA/SNTZMXMFSQLI:(6L IC]],LA/S:-M95MIC5TI,LA/S T -felide-3onstru3tors -fno-e;3e!tions -fno-rtti T VTZ T .B3onfigure T MK T --ena"le-assem"ler T --ena"le-lo3al-infile T --with-mys>ld-userN^Xmys>ldIuserV T --with-uni;-so3ket-!athNBvarBli"Bmys>lBmys>l.so3k T --!refi;NB T --with-e;tra-3harsetsN3om!le; T --e;e3-!refi;N^XIe;e3I!refi;V T --li"e;e3dirN^XIs"indirV T --li"dirN^XIli"dirV T --sys3onfdirN^XIsys3onfdirV T --datadirN^XIdatadirV T --lo3alstatedirNBvarBli"Bmys>l T --infodirN^XIinfodirV T --in3ludedirN^XIin3ludedirV T --mandirN^XImandirV T --with-em"edded-server T --ena"le-thread-safe-3lient T --with-3ommentNTZCffi3ial MySQL 95MTZ4 J Add this for more de"ugging su!!ort J --with-de"ug J Add this for My6SAM 9A6 su!!ort: J --with-raid Z J "en3hdir does not fit in a"ove model. May"e a se!arate "en3h distri"ution make "en3hdirIrootNM95MI:(6L I9CCTBusrBshareB V

Cn3e installed the MySQL data"ase server runtime !arameters 3ould "e modified "y 3hanging the Bet3Bmy.3nf file. :y default the yinst installs an o!timi=ed my.3nf file for small MySQL dataa"ase% "ut on3e the data"ase load and si=e in3reases some of the MySQL !arameters has to "e 3hanged. There are some my.3nf tem!lates !rovided for different MySQL data"ase si=es in B homeByBshareBmys>l dire3tory:

MySQL Administration How-To

)@ BhomeByBshareBmys>l M -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; -r-;r-;r-; & & & & root root root root wheel wheel wheel wheel '@A' '@)# 'ELA &AE@ 0ov 0ov 0ov 0ov )' )' )' )' &##A &##A &##A &##A my-huge.3nf my-large.3nf my-medium.3nf my-small.3nf

ifferent !arameters values in my-small.3nf% my-medium.3nf% my-large.3nf and myhuge.3nf are used de!ending on how "ig and how utili=ed the MySQL data"ase is. Also some !arameters as memory allo3ation for the different memory !ools de!end on the hardware s!e3ifi3ations. ,or instan3e: Rmy-small.3nfS keyI"uffer N )$Q ta"leI3a3he N ' sortI"ufferIsi=e N $'Q netI"ufferIlength N &Q threadIsta3k N $'Q Rmy-huge.3nfS keyI"uffer N A@'M ta"leI3a3he N *)& sortI"ufferIsi=e N &M readI"ufferIsi=e N &M myisamIsortI"ufferIsi=e N $'M threadI3a3he N @ >ueryI3a3heIsi=e N A&M threadI3on3urren3y N @

All the 3hanges in the Bet3Bmy.3nf file are stati3. -ith older MySQL version as A.&A you need to 3hange value in my.3nf and then restart mys>ld and ty!i3ally only administrator 3an do it. And everything de!ending on mys>ld 3an "e affe3ted "y this restart: J yinst restart mys>lIserver yinst: mys>lIserver-'.#.)E: restarting ...

MySQL Administration How-To

)L However% one of the new features in MySQL '.# is the a"ility to 3hange most of MySQL server settings on the fly without restarting the server. Fou 3an <ust use S7T varia"leNnewIvalue synta;. As an e;am!le you might wish !lay with "uffers setting to see how they affe3t !arti3ular >uery. -ith MySQL '.# you don?t need anything more than your regular !rivileges. -hyD :e3ause of one more addition - varia"les now are s!lit into two 3ategories. /lo"al and Session varia"les. /lo"al varia"les affe3t working of whole server while Session varia"les 3hanges are valid for 3urrent session only. Hint: ,or o!timi=ations !ur!oses you 3an run ' 3onne3tions with different settings and e;e3ute same >uery simultaneously ' times doing real-time test without distur"ing anyone with ' restarts. A!!ro!riate 3hanges were made to SHC- +A96A:L7S synta; "y adding /LC:AL\ S7SS6C0 dire3tive to it as des3ri"ed in 3ha!ter '.*.$.' SHC- +A96A:L7S of Manual. mys>lO show varia"les4 mys>lO show varia"les like ?net^?4 .---------------------------.--------------. \ +aria"leIname \ +alue \ .---------------------------.--------------. \ netI"ufferIlength \ @)L& \ \ netIreadItimeout \ A# \ \ netIretryI3ount \ )###### \ \ netIwriteItimeout \ $# \ .---------------------------.--------------. ' rows in set 1#.#) se32 mys>lO set netIwriteItimeoutNA$##4 Query CQ% # rows affe3ted 1#.#* se32 mys>lO show varia"les like ?net^?4 .---------------------------.--------------. \ +aria"leIname \ +alue \ .---------------------------.--------------. \ netI"ufferIlength \ @)L& \ \ netIreadItimeout \ A# \ \ netIretryI3ount \ )###### \ \ netIwriteItimeout \ A$## \ .---------------------------.--------------. ' rows in set 1#.#) se32

MySQL Administration How-To

&# 2. MySQL database structure . database file ty%es

Currently at FahooU two ty!es of MySQL ta"les are used: My6SAM and 6nno : ta"les. 2. .1 MyIS/M tables My6SAM is the default storage engine as of MySQL A.&A. 6t is "ased on the 6SAM 3ode "ut has many useful e;tensions. My6SAM ta"les don?t su!!ort transa3tions% !rimary and foreign Qeys. The main advantages of My6SAM ta"les are faster a33ess 1no transa3tions overhead2% less disk s!a3e usage% less memory usage 7a3h My6SAM ta"le is stored on disk in three files - 1.frm2 % 1.MF 2 and 1.MF62: J ls -la BhomeByBvarBmys>lBdataBmys>lB drw;------ & mys>l users *)& C3t A# &##A . drw;rw;r-; ' mys>l users *)& C3t A# &##A .. -rw-rw---- ) mys>l users # C3t A# &##A 3olumnsI!riv.MF -rw-rw---- ) mys>l users )#&' C3t A# &##A 3olumnsI!riv.MF6 -rw-rw---- ) mys>l users @EE@ C3t A# &##A 3olumnsI!riv.frm -rw-rw---- ) mys>l users A#$ C3t A# &##A d".MF -rw-rw---- ) mys>l users A#E& C3t A# &##A d".MF6 -rw-rw---- ) mys>l users L#@@ C3t A# &##A d".frm -rw-rw---- ) mys>l users # C3t A# &##A fun3.MF -rw-rw---- ) mys>l users )#&' C3t A# &##A fun3.MF6 -rw-rw---- ) mys>l users @$') C3t A# &##A fun3.frm -rw-rw---- ) mys>l users # C3t A# &##A host.MF -rw-rw---- ) mys>l users )#&' C3t A# &##A host.MF6 -rw-rw---- ) mys>l users L#$' C3t A# &##A host.frm -rw-rw---- ) mys>l users # C3t A# &##A ta"lesI!riv.MF -rw-rw---- ) mys>l users )#&' C3t A# &##A ta"lesI!riv.MF6 -rw-rw---- ) mys>l users @@EE C3t A# &##A ta"lesI!riv.frm -rw-rw---- ) mys>l users A#@ 8un && )$:## user.MF -rw-rw---- ) mys>l users &#'@ Aug )L )#:)@ user.MF6 -rw-rw---- ) mys>l users L@#$ C3t A# &##A user.frm

MySQL Administration How-To

&) The files have names that "egin with the ta"le name and have an e;tension to indi3ate the file ty!e.

W.frm? file stores the ta"le definition. W.MF ? 1MF ata2 e;tension stored the data W.MF6? 1MF6nde;2 e;tension stores the inde;es

2. .2 Inno)( 6nno : !rovides MySQL with a transa3tion-safe storage engine with 3ommit% roll"a3k% and 3rash re3overy 3a!a"ilities. 6nno : does lo3king on the row level and also !rovides an Cra3le-style 3onsistent non-lo3king read in S7L7CT statements. These features in3rease multi-user 3on3urren3y and !erforman3e. There is no need for lo3k es3alation in 6nno : "e3ause row-level lo3ks in 6nno : fit in very little s!a3e. 6nno : also su!!orts ,C976/0 Q7F 3onstraints. 6n SQL >ueries you 3an freely mi; 6nno : ty!e ta"les with other ta"le ty!es of MySQL% even within the same >uery. 6nno : has "een designed for ma;imum !erforman3e when !ro3essing large data volumes. 6ts C5( effi3ien3y is !ro"a"ly not mat3hed "y any other disk-"ased relational data"ase engine. ,ully integrated with MySQL Server% the 6nno : storage engine maintains its own "uffer !ool for 3a3hing data and inde;es in main memory. 6nno : stores its ta"les and inde;es in a ta"les!a3e% whi3h may 3onsist of several files 1or raw disk !artitions2. This is different from% for e;am!le% My6SAM ta"les where ea3h ta"le is stored using se!arate files. 6nno : ta"les 3an "e of any si=e even on o!erating systems where file si=e is limited to &/:. ,rom MySQL '.# on% the 6nno : storage engine is ena"led "y default. 6f you don?t want to use 6nno : ta"les% you 3an add the ski!-innod" o!tion to your MySQL o!tion file. 6nno : 3reates ta"les!a3e files in the MySQL data dire3tory "y default. To s!e3ify a lo3ation e;!li3itly% use the innod"IdataIhomeIdir o!tion. JJ 6nno : settings innod"IdataIhomeIdir N BhomeByBvarBmys>lBi"data innod"IdataIfileI!ath N i"data):&*$M:autoe;tend innod"IlogIgrou!IhomeIdir N BhomeByBvarBmys>lBi"log innod"IlogIar3hIdir N BhomeByBvarBmys>lBi"log 6f you s!e3ify no 6nno : 3onfiguration o!tions% MySQL '.# and a"ove 3reates an autoe;tending )#M: data file named Wi"data)? and two *M: log files named Wi"Ilogfile#? and Wi"Ilogfile)? in the MySQL data dire3tory. 16n MySQL '.#.# and '.#.)% the data file is $'M: and not auto-e;tending.2 6n MySQL A.&A% 6nno : will not start if you !rovide no 3onfiguration o!tions.

MySQL Administration How-To

&& 6f you s!e3ify the autoe;tend o!tion for the last data file% 6nno : e;tends the data file if it runs out of free s!a3e in the ta"les!a3e. The in3rement is @M: at a time. 6nno : is not aware of the ma;imum file si=e% so "e 3autious on file systems where the ma;imum file si=e is &/:. To s!e3ify a ma;imum si=e for an auto-e;tending data file% use the ma; attri"ute. 6n the a"ove 3onfiguration the ?i"data)? file is allowed to grow u! to a limit of &*$ M: Fou 3an also use to ta"les!a3e datafiles i"data) and i"data& in the WBi"data? dire3tory: innod"IdataIfileI!athNi"data):*#M:autoe;tend4i"data&:*#M:autoe;tend Two im!ortant disk-"ased resour3es managed "y the 6nno : storage engine are its ta"les!a3e data files and its log files. 6nno : ata : BhomeByBvarBmys>lBi"data

J ls -la BhomeByBvarBmys>lBi"data -rw-rw---- ) mys>l users E@@*&L)*& Se! )A )$:'@ i"data) 6nno : Logs : BhomeByBvarBmys>lBi"log J ls -la BhomeByBvarBmys>lBi"logB -rw-rw---- ) mys>l users $E)#@@$' Se! )A )$:'L i"Ilogfile# -rw-rw---- ) mys>l users $E)#@@$' Se! )) )E:AL i"Ilogfile)

MySQL Administration How-To

You might also like