Ñò ˆ3½Ac@sÜdZddkZddkZddkZddkZddkZddkZddkZddkZddk Z ddkZddk Z dZ dZ d„Z dd d„ƒYZdd d „ƒYZd dd „ƒ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. iÿÿÿÿNs0.1s 2004/11/29cCsZtiƒ\}}}dt|ƒGHdt|ƒGHdt|ƒGHti|||ƒGHdS(Ns exc_type = s exc_value = sexc_traceback = i(tsystexc_infotstrt excepthook(ttypetvaluet traceback((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytExcepts tTestcBseZd„Zd„ZRS(cCsdS(sB Test_Master_Slaves() is not finished. Used to test master/slaves.N((tself((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytTest_Master_Slaves"scCsdS(s: Test_Cluster() is not finished. Used to test the cluster.N((R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt Test_Cluster%s(t__name__t __module__R R (((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyR!s tUtilscBs/eZhd„Zd„Zd„Zd„ZRS(cCsdS(N((R toptions((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__init__.scCsdS(N((R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytSlave_To_Master0scCsdS(N((R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt Add_Slave3scCsdS(N((R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytAdd_Node5s(R R RRRR(((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyR,s   t InstallercBsËeZdZhd„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__($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((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyREsD                   cCsy|iiƒWnnXdS(N(R5tclose(R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__del__ƒscCsDdt|iƒdt|iƒdt|iƒd|i}|S(NsMaster=s:Slave=s :Cluster=t:(RR$R%R&R,(R tstr1((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__str__ˆs@cCs|iS(N(R2(R tother((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__lt__‹scCs|iS(N(R2(R RI((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__le__ŒscCs|iS(N(R2(R RI((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__gt__scCs|iS(N(R2(R RI((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__eq__ŽscCs|iS(N(R2(R RI((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt__ne__scCs |id7_|idd|idƒdG|idGH|iid|idƒt|idd ƒ}|id }|ii|i |ƒ}|i i|i |ƒ}|i i|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 twR9i(R,tCommandR0R5twriteR4R7R:tsubR-R;R.R<R/R=R"R>RD(R tWritetTemplate((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytWrite_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.ROsbash s/scripts/Compile.bashi(R,RQR0(R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytExecute_Compile_Script©sc% Cs|id7_dGHddg}tidƒ}tidƒ}tidƒ}tidƒ}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|idd|dƒ|idd|ƒ|idd|ƒ|idd |dƒ||igg}|i||gƒ|i||gƒ|i|t||ƒgƒ|i| t||ƒgƒ|i|it|iƒgƒ|i|it|iƒgƒ|i|it|i|ƒgƒdX}!|i d"|!d#dYd%|ƒt |dZƒ}t |!d[ƒ}"x|"D]}#|i |#ƒqå W|i ƒ|"i ƒq‰ Wnx÷td=|i|i|id=ƒ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|id=dG|ƒgƒ|i|it|iƒgƒ|i|it|iƒgƒ|d!|}|i d"|d#d]d%|ƒ|id&|}|i d"|d#d'd%|ƒ|id(|}|i d"|d#d)d%|ƒ|i d*|d!|ƒ| d+|d,|id&|d-7} |d.|d,|id(|d-7}|d3|d4|id5|d!|dB7}q= 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__Rt __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:ROs 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.bashRPsL -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/*s export PATH="(R,R8R9R"R$RR'RQtappendtWrite_Templatet Init_InstanceR4RRRDtrangeR%R(R?R&R+R)RARBR*(%R tDirst Re_Instancet Re_PrefixtRe_ExtratRe_Instance_DirtRe_Instance_Cnft Re_DB_PorttRe_DB_IDtRe_NO_Replicast Re_API_Portt Re_API_IDt Re_MGM_IDtStart_File_TexttStop_File_Textt Mysql_Aliast Extra_MastertExtratInstancet Instance_DirRetFilet MySQL_AliasRTtnotS_ExtratC_Extrat Re_Cluster_NotMax_NotMax_No2t Instance2t Instance_Dir2t Init_FiletF2tReadtLineRQ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytSetup_Instances²s†    %%-($$$   %%1 & '    % y # %  3%%1           c CsÈd|id}|id|ƒ|id|id}|idt|iƒ}t|iddƒ}|id ƒ|i|d ƒ|iƒt|id dƒ}|id ƒ|id ƒ|id ƒ|i|dƒ|i|dƒ|i|dƒ|iƒt|iddƒ}|id ƒ|id ƒ|idƒxetd|idƒD]M}|id ƒ|idt|ƒd ƒ|i|dt|ƒdƒq_W|iƒt|iddƒ}|id ƒ|id ƒ|idƒ|i|idƒ|i|idƒ|iƒt|iddƒ}|id ƒ|i|dƒ|i|dƒ|id ƒx^td|idƒD]F}dt|ƒ}|id|}|i|d t|ƒd!ƒq’W|id"ƒ|id#ƒ|i|d$ƒxXtd|idƒD]@}|id%t|ƒd&ƒ|i|dt|ƒd'ƒqW|id(t|id)ƒd*ƒ|iƒt|id+dƒ}|id ƒxÅtd|i|i |idƒD]Ÿ}dt|ƒ}|id|}|id ƒ|i|d,t|ƒd-ƒ|i|d,t|ƒd.ƒ|i|d,t|ƒd/t|ƒd0ƒqÖWd|i}|i }|id ƒ|id1t|ƒd2ƒ|id3ƒ|i|d,t|ƒd4ƒ|id5ƒ|i |idd)} xtd|i|i |idƒD]g}dt|ƒ}|id|}|id ƒ|i|id6t|iƒd7t| |ƒd8ƒ|id1t|ƒd2ƒ|id3ƒ|id9t|ƒd:t| |ƒd;ƒ|i|d,t|ƒd4ƒ|i|id<t|iƒd=t| |ƒd ƒ|id>ƒ|i|id6t|iƒd7t| |ƒd?ƒ|id@ƒq-W|iƒdA|idB}|id|ƒGHdS(CNs mkdir -p s/scriptsROs/bin/mysql -S s /instances(/bin/ndb_mgm --connect-string=127.0.0.1:s/scripts/Cluster_Status.bashRPs 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 Ros /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"RQRR)R4RRRDRsR%R&( R RQtMysqltNDB_MGMRTR‰RRtRangeR((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytCreate_Test_ScriptsÌs®          #       #  #"  % 1     % 7 -7 7 cCs dGH|idd|idƒS(Ns6Starting the mysql services. This could take a minute.ROsbash s/Start(RQR"(R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytStart_Instances5scCs dGH|idd|idƒS(Ns2Stopping mysql services. This could take a minute.ROsbash s/Stop(RQR"(R ((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pytStop_Instances:sRcCsd|GH|id|}|id|ƒ}|ddjo |GHn|ii|dƒd|id}|id|ƒ}|S(NsInitializing: s&/bin/mysql_install_db --defaults-file=ROiischown -R mysql s /instance(R"RQR5RR(R RhRQtResult((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyRr@s  c,CsEd}|id7_tidƒ}|i}t|iƒƒdjoºg}h}d}dddd d d d d ddddg }ytid}WnnXyti|||ƒ\}} Wn|GHti ƒnXx|D]\} } | ||         ÿ i   ’ * ((((RÈR©RºtstatR¿RttypesRÀR8R¸R¢t __version__t Date_VersionRRRR(((sV/hermes/web10/b930/moo.marknielsen/tcu-inc.com/Products/MySQL_Python/Version4/MySQL.pyt s„