mò ˆ3½Ac@s»dZdkZdkZdkZdkZdkZdkZdkZdkZdk Z dkZdk Z dZ dZ d„Z dfd„ƒYZdfd„ƒYZd fd „ƒYZdS( s1 MySQL contains several classes. Only one currently works. "Installer()". Installer will download and install MySQL with maste/slave or cluster combinations. It is currently only made for demonstration purposes and is not meant to be used in a production environment. If you can get the Master/Slave/Cluster instances working on one computer, all you have to do to get it to work on multiple computers is copy over the software, change the config files a little, and then start it up. Copyrighted by Mark E. Nielsen, 11/2004 under the original GPL License. Ns0.1s 2004/11/29cCsZtiƒ\}}}dt|ƒGHdt|ƒGHdt|ƒGHti|||ƒGHdS(Ns exc_type = s exc_value = sexc_traceback = i(tsystexc_infottypetvaluet tracebacktstrt excepthook(RRR((tŠ/MAIN/chroot/Services/apache_tcu-inc/usr/local/apache_tcu-inc/virtual_hosts/www.tcu-inc.com/htdocs/Products/MySQL_Python/Version4/MySQL.pytExcepts tTestcBstZd„Zd„ZRS(NcCsdS(sB Test_Master_Slaves() is not finished. Used to test master/slaves.N((tself((RtTest_Master_Slaves"scCsdS(s: Test_Cluster() is not finished. Used to test the cluster.N((R ((Rt Test_Cluster%s(t__name__t __module__R R (((RR !s tUtilscBs/tZhd„Zd„Zd„Zd„ZRS(NcCsdS(N((R toptions((Rt__init__.scCsdS(N((R ((RtSlave_To_Master0scCsdS(N((R ((Rt Add_Slave3scCsdS(N((R ((RtAdd_Node5s(R RRRRR(((RR,s   t InstallercBsËtZdZhd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zdd„Zd„Zd„Zdd„Zgddd„ZRS(s… This install mysql with master/slave and/or cluster installations. Installer takes one option called "options" which is a hash. cCsÅ||_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d |_ d |_ d |_d |_d |_d|_d|_|iƒ|i|i|i|_|id joti|_ndG|iGHt|idƒ|_|iƒ|_tidƒ|_tidƒ|_tidƒ|_tidƒ|_tidƒ|_ tidƒ|_!tidƒ|_"tidƒ|_#tidƒ|_$tidƒ|_%dS(Ns/usr/local/mysql_clusters/tmp/mysql_install.logiii NiRiðUiØYiÀ]tsmysql-4.1.7.tar.gzs mysql-4.1.7sAftp://mirror.services.wisc.edu/mirrors/mysql/Downloads/MySQL-4.1/s/usr/local/mysql-clusters/usr/local/src/mysql_compilesWriting log file to: tat__MYSQL_FILE__t__MYSQL_COMPILE_DIR__t __FTP_DIR__t __PREFIX__t__COMPILE_HOME__t __M_PORT__t __S_PORT__t __MGM_PORT__t __DB_PORT__t __API_PORT__(&RR toriginal_optionstprefixtlogtmastertslavetclustert master_portt slave_porttcluster_management_porttcluster_db_porttcluster_api_porttnotest mysql_filetmysql_compile_dirtftp_dirt compile_hometDefine_Variablest instances_noRtstouttopent log_handlet Get_Templatest templatestretcompilet re_mysql_filetre_mysql_compile_dirt re_ftp_dirt re_prefixtre_compile_homet re_m_portt re_s_portt re_mgm_portt re_db_portt re_api_port(R R((RREsD                   cCsy|iiƒWnnXdS(N(R R6tclose(R ((Rt__del__ƒscCsDdt|iƒdt|iƒdt|iƒd|i}|S(NsMaster=s:Slave=s :Cluster=t:(RR R%R&R'R-tstr1(R RH((Rt__str__ˆs@cCs|iS(N(R R3(R tother((Rt__lt__‹scCs|iS(N(R R3(R RJ((Rt__le__ŒscCs|iS(N(R R3(R RJ((Rt__gt__scCs|iS(N(R R3(R RJ((Rt__eq__ŽscCs|iS(N(R R3(R RJ((Rt__ne__scCs |id7_|idd|idƒdG|idGH|iid|idƒt|idd ƒ}|id }|i i |i |ƒ}|i i |i|ƒ}|ii |i|ƒ}|ii |i|ƒ}|ii |i|ƒ}|i|ƒ|iƒd S( sl Write_Compile_Script() takes no arguements. It simply compiles and install the binaries for mysql. scompile script written:tcommands mkdir -p s/scriptssCreating script:s/scripts/Compile.bashsWRITE:s/scripts/Compile.bash twR:iN(R R-tCommandR1R6twriteR5tWriteR8tTemplateR;tsubR.R<R/R=R0R>R#R?RE(R RTRU((RtWrite_Compile_Script“s   cCs3|id7_dGH|idd|idƒdS(sx Execute_Compile_Script() takes no arguements and just executes the compile script (which also installs mysql). s compiled:s)Compiling MySQL. This could take a while.RPsbash s/scripts/Compile.bashiN(R R-RRR1(R ((RtExecute_Compile_Script©s c%Cs|id7_dGHddg}tidƒ}tidƒ}"tidƒ}!tidƒ}tid ƒ}tid ƒ}tid ƒ}tid ƒ}tid ƒ}tidƒ}tidƒ}d|id} d|id}d}d}|idjo d}n|dt|iƒd7}|d7}d}|id|}$dG|$GH|idd|$ƒ|idd|$dƒ|idd|$dƒ|idd|$ƒ|idd|$ƒ|idd |$dƒ|!|g|"|igg}|i||$gƒ|i||gƒ|i||$d!|gƒ|$d!|}|id"|d#d$d%|ƒ|id&|}|id"|d#d'd%|ƒ|id(|}|id"|d#d)d%|ƒ|i d*|$d!|ƒ| d+|d,|id&|d-7} |d.|d,|id(|d-7}d/d0|id1|id2}#|#d3|d4|id5|$d!|d67}#t"|$d7d8ƒ}|i$d|id5|$d!|d9ƒ|i$|id5|$d!|d:ƒ|i$|id5|$d!|d;ƒ|i$|id5|$d!|d<ƒ|i%ƒx¶t&d=|i'd=ƒD]ž} d>t| ƒ}|id|}$dG|$GH|idd|$ƒ|idd|$dƒ|idd|$dƒ|idd|$ƒ|idd|$ƒ|idd |$dƒdt|i)| ƒd}|d7}|d?t| ƒd7}|d@t|i)| ƒd7}|!|g|"|igg}|i||$gƒ|i||gƒ|i||$d!|gƒ|i|i+t|iƒgƒ|$d!|}|id"|d#dAd%|ƒ|id&|}|id"|d#d'd%|ƒ|id(|}|id"|d#d)d%|ƒ|i d*|$d!|ƒ| d+|d,|id&|d-7} |d.|d,|id(|d-7}|#d3|d4|id5|$d!|dB7}#q-W|i,djo=dC}|id|}$dG|$GH|idd|$ƒ|idd|$dƒ|idd|$dƒ|idd|$ƒ|idd|$ƒ|idd |$dƒdt| |i-ƒd}|d?t| ƒd7}|#dD|idEt|i/ƒdB7}#tidFƒ} |!|g|"|igg}|i||$gƒ|i||gƒ|i||$d!|gƒ|i| t|i,dGƒgƒ|i|dHgƒ|i|t|i,|i'd=ƒgƒ|i|i1t|i/ƒgƒ|i|i+t|iƒgƒ|$d!|}|id"|d#dId%|ƒ|$dJ}|id"|d#dKd%|ƒ| dL7} | dM7} |i,|i'd=dG}||i,}x±t&d=|i'|i,|i'd=ƒD]‡} dNt| ƒ} |id| } | dO}| dP|dQt|| ƒdRt|i/ƒdSt|| ƒdT|dUt|| ƒdVt|i/ƒdSt|| ƒdW7} dG| GH|idd| ƒ|idd| dƒ|idd| dƒ|idd| ƒ|idd| ƒ|idd | dƒ|"|igg}|i|| gƒ|i|| gƒ|i|t|| ƒgƒ|i|t|| ƒgƒ|i|i1t|i/ƒgƒ|i|i+t|iƒgƒ|i|i7t|i8| ƒgƒdX}|id"|d#dYd%|ƒt"|dZƒ}t"|d[ƒ} x| D]}|i$|ƒqé W|i%ƒ| i%ƒq Wnx÷t&d=|i'|i,|i'd=ƒD]Ñ} d\t| ƒ}|id|}$dG|$GH|idd|$ƒ|idd|$dƒ|idd|$dƒ|idd|$ƒ|idd|$ƒ|idd |$dƒdt| |i-ƒd}|d7}|d?t| ƒd7}|!|g|"|igg}|i||$gƒ|i||gƒ|i||$d!|gƒ|i|td=|i,|i'd=dG| ƒgƒ|i|i1t|i/ƒgƒ|i|i+t|iƒgƒ|$d!|}|id"|d#d]d%|ƒ|id&|}|id"|d#d'd%|ƒ|id(|}|id"|d#d)d%|ƒ|i d*|$d!|ƒ| d+|d,|id&|d-7} |d.|d,|id(|d-7}|#d3|d4|id5|$d!|dB7}#qA Wt"|id^d8ƒ}|i$d_|idBƒ|i$| ƒ|i%ƒt"|id`d8ƒ}|i$|ƒ|i$daƒ|i$dbƒ|i$dcƒ|i$ddƒ|i$deƒ|i%ƒt"|idfd8ƒ}|i$|#ƒ|i%ƒdg|idh}|id|ƒGHdGS(jsSetup_Instances() takes no arguements. This installs the master/slave/cluster instances of mysql. This will create separate data directories for each instance. It will also create a cnf file for each instance. It will initialize the instances. smaster/slave configed:sSetting up the instances.tdatattmpt __INSTANCE__Rt __EXTRA__t__INSTANCE_DIR__t__INSTANCE_CNF__R t __DB_ID__t__NO_REPLICAS__R!t __API_ID__t __MGM_ID__s cd s Ris2log-bin=__PREFIX__/instance/__INSTANCE__/main_log sport=s server-id=1 tmaster1s /instance/s Setting up:RPs mkdir -p s/datas/tmpschown -R mysql schown -R mysql.mysql s chmod 700 s/my.cnf_tfilettemplates my.cnf_mastertre_lists/Start_tstarts/Stop_tstoptcnfsecho Starting s bash s secho Stopping s export PATH=t"s/bin:s/scripts:$PATH" s alias mysql_s='s/bin/mysql --defaults-file=s --local-infile=1' s/first_run.bashRQsL -e "GRANT REPLICATION SLAVE ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY ''" s! -e "create database test_slave" s2 -e "create table table1 (text1 text)" test_slave s4 -e "insert into table1 values ('data')" test_slave iR&s server-id=s report-port=s my.cnf_slaves' tcluster_managementsalias ndb_mgm='s/bin/ndb_mgm 127.0.0.1 t__CLUSTER_NO__it2smy.cnf_cluster_managements/config.ini_cluster_managementsconfig.ini_mgms echo Starting cluster ndb_mgmd. slsu mysql -c './libexec/ndb_mgmd --config-file=./instance/cluster_management/config.ini_cluster_management' t cluster_ndbs /initializeds if [ ! -e 's<' ]; then echo '' echo Initializing cluster s= su mysql -c './libexec/ndbd --initial -c 127.0.0.1:s:id=s' touch s& else echo Starting cluster dbs2 su mysql -c './libexec/ndbd -c 127.0.0.1:s' fi s/tmp/db_temp.cnfs config.ini_dbRtrtcluster_mysqldsmy.cnf_cluster_dbs/Startsexport mysql_prefix='s/Stops%echo Killing ndbd and then ndb_mgmd. skillall ndbd; sleep 2 skillall -q -9 ndbd; sleep 2 skillall ndb_mgmd; sleep 2 s killall -q -0 ndb_mgmd; sleep 2 s /bash_aliasess chmod 755 s/*N(<R R-tDirsR9R:t Re_Instancet Re_PrefixtRe_ExtratRe_Instance_DirtRe_Instance_Cnft Re_DB_PorttRe_DB_IDtRe_NO_Replicast Re_API_Portt Re_API_IDt Re_MGM_IDR#tStart_File_TexttStop_File_Textt Mysql_Aliast Extra_MasterR%tExtraRR(tInstancet Instance_DirRRRftappendtFiletWrite_Templatet Init_Instancet MySQL_AliasR5RTRSREtrangeR&tnoR)tS_ExtraR@R'R,tC_ExtraR*t Re_Cluster_NoRBtMax_NotMax_No2t Instance2t Instance_Dir2t Init_FileRCR+tF2tReadtLine(%R RyRRxR‚RTRzR~RqRŠR”R‘RRRrR‹R•RwR…R’R|RRR{RRuR“RRvRŒRfRŽR€R}RtRsRˆRƒ((RtSetup_Instances²s‚    %% -($$$   %%1 & '    % „ # %  3%%1           c CsÈd|id}|id|ƒ|id|id} |idt|iƒ}t|iddƒ}|i d ƒ|i |d ƒ|i ƒt|id dƒ}|i d ƒ|i d ƒ|i d ƒ|i | dƒ|i | dƒ|i | dƒ|i ƒt|iddƒ}|i d ƒ|i d ƒ|i dƒxet d|i dƒD]M}|i d ƒ|i dt|ƒd ƒ|i | dt|ƒdƒq_W|i ƒt|iddƒ}|i d ƒ|i d ƒ|i dƒ|i |idƒ|i |idƒ|i ƒt|iddƒ}|i d ƒ|i | dƒ|i | dƒ|i d ƒx^t d|i dƒD]F}dt|ƒ}|id|}|i | d t|ƒd!ƒq’W|i d"ƒ|i d#ƒ|i | d$ƒxXt d|i dƒD]@}|i d%t|ƒd&ƒ|i | dt|ƒd'ƒqW|i d(t|i d)ƒd*ƒ|i ƒt|id+dƒ}|i d ƒxÅt d|i |i|i dƒD]Ÿ}dt|ƒ}|id|}|i d ƒ|i | d,t|ƒd-ƒ|i | d,t|ƒd.ƒ|i | d,t|ƒd/t|ƒd0ƒqÖWd|i }|i}|i d ƒ|i d1t|ƒd2ƒ|i d3ƒ|i | d,t|ƒd4ƒ|i d5ƒ|i|i dd)}xt d|i |i|i dƒD]g}dt|ƒ}|id|}|i d ƒ|i |id6t|iƒd7t||ƒd8ƒ|i d1t|ƒd2ƒ|i d3ƒ|i d9t|ƒd:t||ƒd;ƒ|i | d,t|ƒd4ƒ|i |id<t|iƒd=t||ƒd ƒ|i d>ƒ|i |id6t|iƒd7t||ƒd?ƒ|i d@ƒq-W|i ƒdA|idB}|id|ƒGHdS(CNs mkdir -p s/scriptsRPs/bin/mysql -S s /instances(/bin/ndb_mgm --connect-string=127.0.0.1:s/scripts/Cluster_Status.bashRQs s -e show s/scripts/Master_Status.bashsecho secho Status for master. s%/master1/mysql.sock -e 'show status' s*/master1/mysql.sock -e 'show processlist' s,/master1/mysql.sock -e 'show master status' s/scripts/Slave_Status.bashsecho Status for slaves isecho Status for slaves/slaves%/mysql.sock -e 'show slave status\G' s!/scripts/Master_Slave_Status.bashs(echo Status for slaves and then master. s/scripts/Slave_Status.bash s/scripts/Master_Status.bash s/scripts/Master_Slave_Test.bashsE/master1/mysql.sock -v -e 'create database if not exists test_slave' sP/master1/mysql.sock -v -e 'CREATE TABLE if not exists ctest (i INT)' test_slave Rps /instance/s5/master1/mysql.sock -v -e 'insert into ctest values (s)' test_slave s!echo sleeping 2 seconds. sleep 2 secho Getting data from master. sy/master1/mysql.sock -e 'select distinct(i) as slave_no, count(i) as inserts from ctest group by i order by i' test_slave secho Getting data from slaves. sq/mysql.sock -e 'select distinct(i) as slave_no, count(i) as inserts from ctest group by i order by i' test_slave s echo All is" tables should be the same below. s/scripts/Cluster_Test.bashs/cluster_mysqlds?/mysql.sock -v -e 'create database if not exists test_cluster' s\/mysql.sock -v -e 'CREATE TABLE if not exists ctest (i INT) ENGINE=NDBCLUSTER' test_cluster s-/mysql.sock -v -e 'insert into ctest values (s)' test_cluster secho There should be s& distinct entries in the table below. s*echo Each mysqld node entered its own id. s{/mysql.sock -v -e 'select distinct(i) as mysqld_server, count(i) as inserts from ctest group by i order by i' test_cluster s2echo Shutting down each storage node and testing. s/bin/ndb_mgm 127.0.0.1 s -e 's stop' s%echo Getting data from cluster_mysqlds when storage node s is down. s%/libexec/ndbd --nostart -c 127.0.0.1:s:id=s!echo Sleeping 3 seconds. sleep 3 s start' s!echo Sleeping 5 seconds. sleep 5 s chmod 755 s /scripts/*(R R#RRtMysqlRR*tNDB_MGMR5RTRSRER‰R&RŠRR‘R'tRangeRŽ( R RR˜RŠR‘R™RŽRTRRR—((RtCreate_Test_ScriptsÌs®          #       #  #"  % 1     % 7 -7 7 cCs dGH|idd|idƒS(Ns6Starting the mysql services. This could take a minute.RPsbash s/Start(R RRR#(R ((RtStart_Instances5scCs dGH|idd|idƒS(Ns2Stopping mysql services. This could take a minute.RPsbash s/Stop(R RRR#(R ((RtStop_Instances:sRcCsd|GH|id|}|id|ƒ}|ddjo |GHn|ii|dƒd|id}|id|ƒ}|S(NsInitializing: s&/bin/mysql_install_db --defaults-file=RPiischown -R mysql s /instance(RiR R#RRtResultR6RS(R RiRRR((RR‡@s  c CsEd}|id7_tidƒ}|i}t|i ƒƒdjoºg}h}d} dddd d d d d ddddg }ytid}WnnXyti|| |ƒ\}} Wn|GHtiƒnXx|D]\}} | ||R"RtlentkeystArgstoptlisttOptstLongRtargvtgetopttoptstargstexittoRthas_keytintR(R)R,R+tcluster_mgm_portR#tsearchR$R5tLogRSREtLogFileR%R&RŠR't Download_BadtDownloadRtRe_TGZtstringtsplittTempR.RVR/R0R(R RµR±R R¦R¤RŠR£R>R¸RªR¥RR³R¬R´RR©((RR2Lsô *            "  cCs@|id7_h}d|d         ÿ i   ’ * (RÉR¶R½tstatRÀRttypesRÂR9R¹R¨t __version__t Date_VersionRR RR(RÊR¶RRRÂRRR9R¹RÍRÀR R¨RÌR½RË((Rt? sc