MySQL Training Part1

download MySQL Training Part1

of 23

Transcript of MySQL Training Part1

  • 8/13/2019 MySQL Training Part1

    1/23

  • 8/13/2019 MySQL Training Part1

    2/23

    )

    Contents

    1. General Information................................................................... 2

    1.1 Internals and Portability .............................................................. 21.2 Security ....................................................................................... 21.3 Scalability and Limits .................................................................. 31.4 Connectivity ................................................................................ 31.5 Localization ................................................................................. 31.6 Clients and Tools ......................................................................... 41. Com!arison o" #yS$L %it& Post'reS$L ...................................... 4

    2. Installation and configuration of MySQL...............................

    2.1 Installation o" #yS$L on (ree)S* mac&ines ..............................

    2.2 #yS$L data"iles location.............................................................. 2.3 #yS$L t&reads and database connection ................................... 132.4 #yS$L con"i'uration ................................................................... 162.5 #yS$L database structure + database "ile ty!es ........................ 2,

    3. Security.........................................................................................

    )ac-u! and ecovery .........................................................................Corru!tion ..........................................................................................

    Tunin' ................................................................................................

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    3/23

    &

    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(sif availa"le.

    - +ery fast -tree disk ta"les with inde; 3om!ression and thread-"ased memoryallo3ation system.

    - +ery fast

  • 8/13/2019 MySQL Training Part1

    4/23

    - (! to & inde;es !er ta"le. 7a3h inde; may 3onsist of ) to )$ 3olumns or !arts of3olumns.

    - The ma;imum inde; width is *## "ytes 1this may "e 3hanged when 3om!ilingMySQL 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;2or 0amed 5i!es 10T2.

    - All 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 at3om!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 aswell.

    - All MySQL !rograms 3an "e invoked with the --hel! or -D o!tions to o"tain on-lineassistan3e.

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    5/23

    '

    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 mostly-read-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 neverhave 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(5AT7 and 7L7T7 3ommands and to !erform statisti3s analyses that are 3riti3al toget good !erforman3e with 5ostgreSQL.

    +AC((M is also needed after adding a lot of new rows to a ta"le. n a "usy systemwith lots of 3hanges% +AC((M must "e run very fre>uently% in the worst 3ases evenmany 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 fun3tions than 5ostgreSQL.

    - M79/7 ta"les gives a uni>ue way to instantly make a view over a set of identi3alta"les and use these as one. This is !erfe3t for systems where you have log files thatyou 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 inthe 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!eedadvantage in multi-user a!!li3ations and also makes it easier for MySQL Server totake 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 (5AT7B7L7T7 grants !eruser 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

  • 8/13/2019 MySQL Training Part1

    6/23

    *

    - MySQL Server also allows you to s!e3ify the !rivilege on host and user3om"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 6nno2 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 andta"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. Are!air tool is only needed when a !hysi3al 3orru!tion of a datafile ha!!ens% usuallyfrom a hardware failure. 6t allows a ma

  • 8/13/2019 MySQL Training Part1

    7/23

    $

    Currently su!!orted featured in MySQL Server:

    ,eatures MySQL version

    Su" sele3ts '.)

    ,oreign keys '.) 1.& with 6nno2

    +iews *.#

    Stored !ro3edures *.#

    Triggers *.#

    (nions '.#

    ,ull

  • 8/13/2019 MySQL Training Part1

    8/23

    E

    2.Installation and confi&uration of MySQL

    2.1 Installation of MySQL on 'ree(S) mac*ines

    MySQL server and 3lient Gyinst !a3kages are availa"le at:

    htt!:BBdist.3or!.yahoo.3omB"y-3ategoryBmys>lBmys>lIserverhtt!:BBdist.3or!.yahoo.3omB"y-3ategoryBmys>lBmys>lI3lient

    efore installing the mys>lIserver or mys>lI3lient !a3kages% 3he3k their de!enden3iesfrom the Gde!enden3ies gra!h. To install on a lo3al ma3hine use these 3ommands 1asGroot user2:

    J yinst install mys>lIserverJ yinst install mys>lI3lient

    This will !i3k u! the 3urrent sta"le version of these !rodu3ts. 6f you need to installolder version% go the a"ove (9Ls and use the e;a3t mys>lIserver or mys>lI3lient

    verisons. 7;am!le 1as Groot user2:

    J yinst install mys>lIserver-'.#.)IJ yinst install mys>lI3lient-.&.*)

    The Gyinst installation 3ommand will 3reate the MySQL installation and data"asedire3tories% install the MySQL Gmys>l 3onfiguration data"ase% install the MySQLGtest test data"ase and 3reate the Bet3Bmy.3nf 1MySQL 3onfiguration2 file. y default%the Gmys>l data"ase has no se3urity enfor3ed and there is no !assword for MySQLGroot user.

    2.2 MySQL datafiles location +binary files, confi&uration files, lo& files, datafiles-

    y default the yinst installs the MySQL data"ase "inaries into BhomeByB"inB :

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    9/23

    @

    J 3d BhomeByB"inB

    J ls -la mys>lK

    -r-;r-;r-; & root wheel )@$*#$ Mar &$ # mys>l-r-;r-;r-; & root wheel *E' Mar &$ # mys>lI3onfig-r-;r-;r-; & root wheel &@# Aug ' # mys>lI3onvertIta"leIformat-r-;r-;r-; & root wheel )#'&& Aug ' # mys>lIe;!lainIlog-r-;r-;r-; & root wheel &$*E Aug ' # mys>lIfindIrows-r-;r-;r-; & root wheel '@$ Aug ' # mys>lIfi;Ie;tensions-r-;r-;r-; & root wheel $ Aug ' # mys>lIfi;I!rivilegeIta"les-r-;r-;r-; & root wheel &$)@ Aug ' # mys>lIftIdum!-r-;r-;r-; & root wheel )$$' Aug ' # mys>lIinstall-r-;r-;r-; & root wheel )')$' Aug ' # mys>lIinstallId"-r-;r-;r-; & root wheel $)@$ Aug ' # mys>lIse3ureIinstallation-r-;r-;r-; & root wheel )E&E@ Aug ' # mys>lIset!ermission-r-;r-;r-; & root wheel )$*# Aug ' # mys>lIta"leinfo-r-;r-;r-; & root wheel )&$ Aug ' # mys>lI=a!

    -r-;r-;r-; & root wheel )))* Mar &$ # mys>la33ess-r-;r-;r-; & root wheel &@)E# Mar &$ # mys>ladmin-r-;r-;r-; & root wheel *'# Aug ' # mys>l"inlog-r-;r-;r-; & root wheel )#@) Aug ' # mys>l"ug-r-;r-;r-; & root wheel &)$#) Mar &$ # mys>l3he3k-r-;r-;r-; & root wheel )@&* Aug ' # mys>ldImulti-r-;r-;r-; & root wheel )#'*@ Aug ' # mys>ldIsafe-r-;r-;r-; & root wheel $*) Mar &$ # mys>ldum!-r-;r-;r-; & root wheel '@ Aug ' # mys>ldum!slow-r-;r-;r-; & root wheel )&&) Aug ' # mys>lhot3o!y-r-;r-;r-; & root wheel )E# Mar &$ # mys>lim!ort

    Fou should have this !ath added to your user a33ount ."ashI!rofile on the MySQLdata"ase server or you 3an do that on the fly:

    e;!ort 5ATHN5ATH:BhomeByB"in

    MySQL 3onfiguration files sear3h order is first in the user?s home dire3tory and thento the Bet3B dire3tory. This allow ea3h user to have it?s own my.3nf file in it?s own homedire3tory and1or2 one glo"al Bet3Bmy.3nf file. Fahoo?s yinst Gmys>lIserver 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:

    ls -la Bet3Bmy.3nflrw;r-;r-; ) root wheel )@ Mar ' #' Bet3Bmy.3nf -O BhomeByBet3Bmy.3nf

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    10/23

    MySQL data"ase server 3onfiguration file 1my.3nf2 has the data"ase !arameters as:

    "asedir - MySQL installation root dire3torydatadir - MySQL datafiles dire3torylog-error - MySQL error log dire3torytm!dir - MySQL tem!orary dire3tory!id-file - 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 GJ to !ut 3omments into the 3onfiguration file. lank s!a3es are notenfor3ed% 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 #$so3ket N Btm!Bmys>l.so3kuser N mys>lski!-lo3kingset-varia"le N keyI"ufferN&Mset-varia"le N ma;IallowedI!a3ketN@Mset-varia"le N ta"leI3a3heN&*$set-varia"le N sortI"ufferN*)&set-varia"le N netI"ufferIlengthN@set-varia"le N myisamIsortI"ufferIsi=eN)$M

    set-varia"le N ma;I3onne3tIerrorsNset-varia"le N ma;I3onne3tionsN#"asedir N BhomeBydatadir N BhomeByBvarBmys>lBdatalog-error N BhomeByBlogsBmys>lBmys>ld.errtm!dir N Btm!B!id-file N BhomeByBvarBmys>lBmys>ld.!id

    JJ avoid ,reeS 0S !ro"lemsski!-name-resolve

    JJ (n3omment these if this server will "e a master.

    log-"inserver-id N )

    JJ 6nno settings

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

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    11/23

    )#

    innod"IlogIgrou!IhomeIdir N BhomeByBvarBmys>lBi"log

    innod"IlogIar3hIdir N BhomeByBvarBmys>lBi"logset-varia"le N innod"I"ufferI!oolIsi=eN)&@Mset-varia"le N innod"IadditionalImemI!oolIsi=eN&Mset-varia"le N innod"IlogIfileIsi=eN$'Mset-varia"le N innod"IlogI"ufferIsi=eN@Minnod"IflushIlogIatItr;I3ommitN)set-varia"le N innod"Ilo3kIwaitItimeoutN##

    JJ Query 3a3he

    >ueryI3a3heIsi=e N )$M>ueryI3a3heIty!e N )

    Rmyisam3hkset-varia"le N keyI"ufferNM

    set-varia"le N sortI"ufferNMset-varia"le N readI"ufferN&Mset-varia"le N writeI"ufferN&M

    MySQL data"ase server has two default log files lo3ated into the BhomeByBlogsBmys>lBdire3tory:

    J ls -la BhomeByBlogsBmys>lB-rw-r--r-- ) root users *$ 8un E ):*$ mys>l.log-rw-rw---- ) mys>l users * Se! #E:# 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#)&) )#:#:&' mys>ld ended

    Starting mys>ld daemon with data"ases from BhomeByBvarBmys>lBdatailling mys>ld with !id &*ait for mys>ld to e;it3#)&) )#:#E:#' mys>ld endeddone

    Starting mys>ld daemon with data"ases from BhomeByBvarBmys>lBdatailling mys>ld with !id &)ait for mys>ld to e;it3#)&) )':&@:#' mys>ld ended

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

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    12/23

    ))

    6nno: 7rror: Mem area si=e is #. 5ossi"ly a memory overrun of the6nno: !revious allo3ated areaU

    6nno: A!!arent memory 3orru!tion: mem dum! len *##4 he;EE)"@######f$dEE*f"#E*&d#E#$E*E&&e$##)3#######)######)#EdEE))#EdEE)################a@######################a@######'###############$$'d*$#'*#*)e*d$#e$$'d)@E)'#############################################@###&f##&"###&)##)a##)'##)##)######@''*)4 as3 w......NwI...-#!3ur.3..........Vw..V................................dN*W.F.Q...idN)@E)'..........................B..2.U...........Q............:..".W..w................:...Xd!............................)'*&.)E@$)E.dailyI"IdataI3am!aignIadsI&.............NwI.h.w#sel.3.....................................Y...Y...........).)@.&'.&E.$')'#@.*......................................................................................................................................................46nno: S3anning "a3kward trying to find !revious allo3ated mem "lo3ksMem "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 serverduring >uery 1serverIerrnoN)2#'#@&@ $:##:## Slave 6B thread: ,ailed reading log event% re3onne3ting to retry% log?mdr)-"in.)$E? !osition )#)#$@#'#@&@ $:##:# 7rror reading !a3ket from server: Lost 3onne3tion to MySQL serverduring >uery 1serverIerrnoN)2#'#@&@ $:##:# Slave 6B thread: ,ailed reading log event% re3onne3ting to retry% log?mdr)-"in.)$? !osition '#'#@& $:##:## 7rror reading !a3ket from server: error reading log entry

    1serverIerrnoN)&$2#'#@& $:##:## /ot fatal error )&$: ?error reading log entry? from master whenreading data from "inary log#'#@& $:##:## Slave 6B thread e;iting% read u! to log ?mdr)-"in.)E#?% !osition '#'#@& &&:*':) Slave 6B thread: 3onne3ted to master?re!lYmdr).data.yahoo.3om:#$?% re!li3ation started in log ?mdr)-"in.)E#? at!osition '#'##) )):&&:&E Slave 6B thread e;iting% read u! to log ?mdr)-"in.)E@?% !osition '#'##) )):&&:& Slave 6B thread: 3onne3ted to master?re!lYmdr).data.yahoo.3om:#$?% re!li3ation started in log ?mdr)-"in.)E@? at!osition '#'##) ):#&:# Slave: re3eived # length !a3ket from server% a!!arent master

    shutdown:#'##) ):#&:# Slave 6B thread: ,ailed reading log event% re3onne3ting to retry%log ?mdr)-"in.)E? !osition '#'##) ):#&:# Slave 6B thread: error re3onne3ting to master?re!lYmdr).data.yahoo.3om:#$?: 7rror: ?Lost 3onne3tion to MySQLserver during >uery? errno: ) retry-time: $# retries: @$'##7999: ))'$ Ta"le ?M9.M9IataSet? doesn?t e;ist#'##) ):#E:)E Slave: 7rror ?Ta"le ?M9.M9IataSet? doesn?t e;ist? on >uery

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    13/23

    )&

    ?u!date M9IataSet set validto N ?#'-#-#) ):#$:*'? where 1oid N )#@*' andvalidfrom PN ?#'-#-#) ):#$:*'? and validto N ?-)&-) &:*:*?2? 1defaultdata"ase was ?M9?2% errorI3odeN))'$#'##) ):#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 )*#@'#'##) ):)#:)# Slave 6B thread e;iting% read u! to log ?mdr)-"in.)@)?% !osition')*@#'##) ):):*# Slave 6B thread: 3onne3ted to master?re!lYmdr).data.yahoo.3om:#$?% re!li3ation started in log ?mdr)-"in.)@)? at!osition '

    (sually% ea3h line in the mys>ld.err file is started with the date formated asGFFMM and the time stam! formated as GHH&':M6:SS

    The main MySQL data"ase files dire3tory is BhomeByBvarBmys>l . 6n this dire3tory arestored the My6SAM and 6nno data"ase files:

    ls -la BhomeByBvarBmys>ltotal $drw;rw;r-; * mys>l users *)& Aug &' )):## .drw;r-;r-; @ root wheel *)& 8un E )):** ..drw;rw;r-; * mys>l users *)& Se! ) ):) datadrw;rw;r-; & mys>l users *)& 8un E )):** i"datadrw;rw;r-; & mys>l users *)& 8un E )):** i"log

    The My6SAM datafiles are stored in the BhomeByBvarBmys>lBdata dire3tory. 7a3hMySQL data"ase has su"-dire3tory into this dire3tory. ,or instan3e in the followinge;am!le there are three su"-dire3tories for three different MySQL data"ases [ M9%mys>l and test:

    ls -la BhomeByBvarBmys>lBdatatotal '$&&@)drw;rw;r-; * mys>l users *)& Se! ) ):) .drw;rw;r-; * mys>l users *)& Aug &' )):## ..

    drw;------ & mys>l users *)& Se! ) ):)) M9drw;------ & mys>l users *)& 8un E )):** mys>ldrw;------ & mys>l users *)& Aug )& #@:) test

    y default two MySQL data"ases Gmys>l and Gtest are 3reated "y the yinst.

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    14/23

    )

    Two im!ortant disk-"ased resour3es managed "y the 6nno storage engine are itsta"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@@*&)*& Se! ) )$:'@ i"data)

    6nno Logs : BhomeByBvarBmys>lBi"log

    J ls -la BhomeByBvarBmys>lBi"logB

    -rw-rw---- ) mys>l users $E)#@@$' Se! ) )$:' i"Ilogfile#-rw-rw---- ) mys>l users $E)#@@$' Se! )) )E: i"Ilogfile)

    2.3 MySQL t*reads and database connection

    MySQL data"ase server is running as se!arate thread !ro3essed started "y theMySQL start !rogram [ mys>ldIsafe:

    !s -au;w \ gre! mys>ldIsaferoot @@&' #.# #.) $*$ )@@ !E 6 )):*EAM #:##.#) B"inBsh BhomeByB"inBmys>ldIsafe --datadirNBhomeByBvarBmys>lBdata [!id-file

    The mys>ldIsafe starts the MySQL thread !ro3esses:

    !s au;w \ gre! mys>ld \ gre! -v mys>ldIsafe \ 3ut -d Z-Z -f)mys>l @@* #.# ).) )))EE$ & !E 6 )):*EAM #:##.)* BhomeByBli"e;e3Bmys>ldmys>l @@$# #.# ).) )))EE$ & !E S )):*EAM #:##.# BhomeByBli"e;e3Bmys>ldmys>l @@$) #.# ).) )))EE$ & !E 6 )):*EAM #:##.## BhomeByBli"e;e3Bmys>ldmys>l @@$& #.# ).) )))EE$ & !E 6 )):*EAM #:##.## BhomeByBli"e;e3Bmys>ld

    mys>l @@$ #.# ).) )))EE$ & !E 6 )):*EAM #:##.#) BhomeByBli"e;e3Bmys>ldmys>l @@$' #.# ).) )))EE$ & !E 6 )):*EAM #:##.## BhomeByBli"e;e3Bmys>ldmys>l @@$* #.# ).) )))EE$ & !E 6 )):*EAM #:##.## BhomeByBli"e;e3Bmys>ldmys>l @@$$ #.# ).) )))EE$ & !E S )):*EAM #:#&. BhomeByBli"e;e3Bmys>ldmys>l @@$E #.# ).) )))EE$ & !E 6 )):*EAM #:##.## B

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    15/23

    )'

    homeByBli"e;e3Bmys>ldmys>l @@$@ #.# ).) )))EE$ & !E 6 )):*EAM #:##.## BhomeByBli"e;e3Bmys>ld

    To test the MySQL data"ase 3onne3tion% you have to have a valid a33ount and knowits !assword. The 3onne3t strinng 3ould in3lude the MySQL data"ase you want to3onne3t to:

    mys>l -u root mys>l9eading 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 g.Four MySQL 3onne3tion id is to server version: '.#.)E-Fahoo-SM5

    Ty!e ?hel!4? or ?h? for hel!. Ty!e ?3? 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>l as user Grootand >uery the ta"les in this data"ase.

    e 3an also use the Gmys>l 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 g.Four MySQL 3onne3tion id is )# to server version: '.#.)E-Fahoo-SM5

    Ty!e ?hel!4? or ?h? for hel!. Ty!e ?3? to 3lear the "uffer.

    mys>lO show ta"les47999 )#'$: 0o ata"ase Sele3ted

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    16/23

    )*

    Sin3e we didn?t s!e3ify a MySQL on 3onne3t time% we are getting an error when tryingto >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>l49eading 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 test49eading 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

  • 8/13/2019 MySQL Training Part1

    17/23

    )$

    mys>lO show ta"les4-----------------------------\ Ta"lesIinItest \-----------------------------\ TS5709759TI) \-----------------------------) 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 alittle 3ontrol over how the !a3kage was "uild% unless you "uild the MySQL !a3kagewith 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 BhomeByBshareBmys>lBmys>l-PversionO.s!e3 file.

    PtrifonYwineOBhomeByBshareBmys>l

    -r-;r-;r-; & root wheel &'*)) 0ov )' # mys>l-'.#.)E.s!e3

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

    uildMySQL12 XJ The --ena"le-assem"ler sim!ly does nothing on systems that does notJ su!!ort assem"ler s!eedu!s.sh -3 Z5ATHNZXMFSQLI(6LI5ATH:-5ATHVZ CCNZXCC:-MFSQLI(6LICCVZ

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    18/23

    )E

    C]]NZXC]]:-MFSQLI(6LIC]]VZ C,LA/SNZXMFSQLI(6LIC,LA/S:-95MI5TI,LA/SVZ C]],LA/SNZXMFSQLI(6LIC]],LA/S:-95MI5TI,LA/S -felide-3onstru3tors -fno-e;3e!tions -fno-rtti VZ .B3onfigure K --ena"le-assem"ler --ena"le-lo3al-infile --with-mys>ld-userN^Xmys>ldIuserV --with-uni;-so3ket-!athNBvarBli"Bmys>lBmys>l.so3k --!refi;NB --with-e;tra-3harsetsN3om!le; --e;e3-!refi;N^XIe;e3I!refi;V --li"e;e3dirN^XIs"indirV --li"dirN^XIli"dirV --sys3onfdirN^XIsys3onfdirV --datadirN^XIdatadirV

    --lo3alstatedirNBvarBli"Bmys>l --infodirN^XIinfodirV --in3ludedirN^XIin3ludedirV --mandirN^XImandirV --with-em"edded-server --ena"le-thread-safe-3lient --with-3ommentNZffi3ial MySQL 95MZ4 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"utionmake "en3hdirIrootN95MI(6LI9TBusrBshareBV

    n3e installed the MySQL data"ase server runtime !arameters 3ould "e modified "y3hanging the Bet3Bmy.3nf file. y default the yinst installs an o!timi=ed my.3nf file forsmall MySQL dataa"ase% "ut on3e the data"ase load and si=e in3reases some of theMySQL !arameters has to "e 3hanged.

    There are some my.3nf tem!lates !rovided for different MySQL data"ase si=es in BhomeByBshareBmys>l dire3tory:

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    19/23

    )@

    BhomeByBshareBmys>l

    -r-;r-;r-; & root wheel '@' 0ov )' # my-huge.3nf-r-;r-;r-; & root wheel '@)# 0ov )' # my-large.3nf-r-;r-;r-; & root wheel 'E 0ov )' # my-medium.3nf-r-;r-;r-; & root wheel &E@ 0ov )' # my-small.3nf

    ifferent !arameters values in my-small.3nf% my-medium.3nf% my-large.3nf and my-huge.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 onthe hardware s!e3ifi3ations.

    ,or instan3e:

    Rmy-small.3nf

    keyI"uffer N )$ta"leI3a3he N 'sortI"ufferIsi=e N $'netI"ufferIlength N &threadIsta3k N $'

    Rmy-huge.3nf

    keyI"uffer N @'M

    ta"leI3a3he N *)&sortI"ufferIsi=e N &MreadI"ufferIsi=e N &MmyisamIsortI"ufferIsi=e N $'MthreadI3a3he N @>ueryI3a3heIsi=e N &MthreadI3on3urren3y N @

    All the 3hanges in the Bet3Bmy.3nf file are stati3. ith older MySQL version as .&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 thisrestart:

    J yinst restart mys>lIserveryinst: mys>lIserver-'.#.)E: restarting ...

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    20/23

    )

    However% one of the new features in MySQL '.# is the a"ility to 3hange most ofMySQL server settings on the fly without restarting the server. Fou 3an uery. ith MySQL '.# you don?t need anything morethan 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 whileSession varia"les 3hanges are valid for 3urrent session only.

    Hint: ,or o!timi=ations !ur!oses you 3an run ' 3onne3tions with different settingsand e;e3ute same >uery simultaneously ' times doing real-time test withoutdistur"ing anyone with ' restarts.

    A!!ro!riate 3hanges were made to SH +A96AL7S synta; "y adding /LAL\S7SS60 dire3tive to it as des3ri"ed in 3ha!ter '.*.$.' SH +A96AL7S of Manual.

    mys>lO show varia"les4

    mys>lO show varia"les like ?net^?4-----------------------------------------\ +aria"leIname \ +alue \-----------------------------------------\ netI"ufferIlength \ @)& \\ netIreadItimeout \ # \\ netIretryI3ount \ )###### \\ netIwriteItimeout \ $# \-----------------------------------------

    ' rows in set 1#.#) se32

    mys>lO set netIwriteItimeoutN$##4Query % # rows affe3ted 1#.#* se32

    mys>lO show varia"les like ?net^?4-----------------------------------------\ +aria"leIname \ +alue \-----------------------------------------\ netI"ufferIlength \ @)& \\ netIreadItimeout \ # \

    \ netIretryI3ount \ )###### \\ netIwriteItimeout \ $## \-----------------------------------------' rows in set 1#.#) se32

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    21/23

    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 .&. 6t is "ased on the 6SAM 3ode"ut has many useful e;tensions. My6SAM ta"les don?t su!!ort transa3tions% !rimaryand foreign eys. The main advantages of My6SAM ta"les are faster a33ess 1notransa3tions overhead2% less disk s!a3e usage% less memory usage

    7a3h My6SAM ta"le is stored on disk in three files - 1.frm2 % 1.MF2 and 1.MF62:

    J ls -la BhomeByBvarBmys>lBdataBmys>lB

    drw;------ & mys>l users *)& 3t # # .drw;rw;r-; ' mys>l users *)& 3t # # ..-rw-rw---- ) mys>l users # 3t # # 3olumnsI!riv.MF-rw-rw---- ) mys>l users )#&' 3t # # 3olumnsI!riv.MF6-rw-rw---- ) mys>l users @EE@ 3t # # 3olumnsI!riv.frm

    -rw-rw---- ) mys>l users #$ 3t # # d".MF-rw-rw---- ) mys>l users #E& 3t # # d".MF6-rw-rw---- ) mys>l users #@@ 3t # # d".frm

    -rw-rw---- ) mys>l users # 3t # # fun3.MF

    -rw-rw---- ) mys>l users )#&' 3t # # fun3.MF6-rw-rw---- ) mys>l users @$') 3t # # fun3.frm

    -rw-rw---- ) mys>l users # 3t # # host.MF-rw-rw---- ) mys>l users )#&' 3t # # host.MF6-rw-rw---- ) mys>l users #$' 3t # # host.frm

    -rw-rw---- ) mys>l users # 3t # # ta"lesI!riv.MF-rw-rw---- ) mys>l users )#&' 3t # # ta"lesI!riv.MF6-rw-rw---- ) mys>l users @@EE 3t # # ta"lesI!riv.frm

    -rw-rw---- ) mys>l users #@ 8un && )$:## user.MF

    -rw-rw---- ) mys>l users '@ Aug ) )#:)@ user.MF6-rw-rw---- ) mys>l users @#$ 3t # # user.frm

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    22/23

    &)

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

    W.frm? file stores the ta"le definition. W.MF? 1MFata2 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 ra3le-style 3onsistent non-lo3king read in S7L7CT statements. Thesefeatures in3rease multi-user 3on3urren3y and !erforman3e. There is no need for lo3kes3alation in 6nno "e3ause row-level lo3ks in 6nno fit in very little s!a3e. 6nnoalso su!!orts ,976/0 7F 3onstraints. 6n SQL >ueries you 3an freely mi; 6nnoty!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 datavolumes. 6ts C5( effi3ien3y is !ro"a"ly not mat3hed "y any other disk-"ased relationadata"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 andinde;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 usingse!arate files. 6nno ta"les 3an "e of any si=e even on o!erating systems where filesi=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!tionfile.

    6nno 3reates ta"les!a3e files in the MySQL data dire3tory "y default. To s!e3ify alo3ation e;!li3itly% use the innod"IdataIhomeIdir o!tion.

    JJ 6nno settings

    innod"IdataIhomeIdir N BhomeByBvarBmys>lBi"datainnod"IdataIfileI!ath N i"data):&*$M:autoe;tendinnod"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 auto-e;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 fileis $'M and not auto-e;tending.2 6n MySQL .&% 6nno will not start if you !rovideno 3onfiguration o!tions.

    MySQL Administration How-To

  • 8/13/2019 MySQL Training Part1

    23/23

    &&

    6f you s!e3ify the autoe;tend o!tion for the last data file% 6nno e;tends the data fileif 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 wherethe ma;imum file si=e is &/. To s!e3ify a ma;imum si=e for an auto-e;tending datafile% use the ma; attri"ute. 6n the a"ove 3onfiguration the ?i"data)? file is allowed togrow 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 itsta"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@@*&)*& Se! ) )$:'@ i"data)

    6nno Logs : BhomeByBvarBmys>lBi"log

    J ls -la BhomeByBvarBmys>lBi"logB

    -rw-rw---- ) mys>l users $E)#@@$' Se! ) )$:' i"Ilogfile#

    -rw-rw---- ) mys>l users $E)#@@$' Se! )) )E: i"Ilogfile)