mysql每幾個小時匯入幾條資料到線上

來源:互聯網
上載者:User

標籤:

 1 由於公司需要,需要將線下的資料庫每幾個小時導幾條資料到線上資料庫中 2   3 [[email protected] bbs]# rpm -qa | grep "expect" 4 expect-5.44.1.15-5.el6_4.x86_64 5 如果沒有 yum -y install expect 6   7 1,ssh映射  8 ssh_bbs.sh 9 #!/usr/bin/expect10 set timeout 20 11 spawn ssh -C -f -N -g -i id_dsa(密鑰)  -L 本機ip:20222(映射到原生連接埠):線下內網dbhosts:3306 [email protected]外網ip  -p2212 expect "*passphrase*"13 send "wdzjdsakey\r"14 expect "suspend"15  16 2,ps_ssh.sh17 ps -ef | grep "192.168.11.45:20222" | grep -v grep18 if [ $? != 0 ]19 then20      ./ssh_bbs.sh21 fi22  23 3,mysql_export.py24 #!/usr/bin/python25 import MySQLdb26 import time27 import commands,sys28 import subprocess29 30 times=time.strftime(‘%Y-%m-%d-%H:%M:%S‘)31 32 def cmd(mysql_cmd):33      (status,output)=commands.getstatusoutput(mysql_cmd)34      if status == 0:35           print mysql_cmd+‘...is ok‘36      elif status == 256:37           print ‘yes‘38           print mysql_cmd+‘...is ok‘39      else:40           sys.exit(1)41 42 conn=MySQLdb.connect(‘192.168.11.23‘,‘root‘,‘root‘,‘test‘,charset=‘utf8‘)43 cur=conn.cursor()44 cur.execute("select id from wenda_question order by id  desc")45 #cur.execute("select id from wenda_question")46 mem=047 for i in  cur.fetchall():48      mem+=149      if mem>20:50           mem=051           time.sleep(3600)52           cmd("kill -9 `ps -ef | grep ‘192.168.11.45:20222‘| grep -v grep|awk ‘{print $2}‘|xargs`")53           time.sleep(30)54           subprocess.Popen("sh ps_ssh.sh",subprocess.PIPE,shell = True)55           time.sleep(20)56           cmd(‘ps -ef | grep "192.168.11.45:20222" | grep -v grep‘)57           print times58      question=‘mysqldump -uroot -proot -h192.168.11.23 --skip-add-drop-table test wenda_question -w "id=‘+str(i[0])+‘">wenda_question.sql‘59      answer=‘mysqldump -uroot -proot -h192.168.11.23 --skip-add-drop-table test wenda_answer -w "qid=‘+str(i[0])+‘">wenda_answer.sql‘60      question_import=‘mysql -uwdzj -pwdzj_2014_bbsnew -h192.168.11.45 -P 20222 -f wdzj_wenda  < wenda_answer.sql‘61      answer_import=‘mysql -uwdzj -pwdzj_2014_bbsnew -h192.168.11.45 -P 20222 -f wdzj_wenda  < wenda_question.sql‘62      cmd(question)63      cmd(answer)64      cmd(question_import)65      cmd(answer_import)

 

mysql每幾個小時匯入幾條資料到線上

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.