Python Split sql file

Source: Internet
Author: User

Before using Joomla to help a school to make a website, and then to deploy to them to the server, they only provide sftp and phpMyAdmin account, upload website file is quite smooth, But later with phpMyAdmin import MySQL data on the problem: because they set the phpMyAdmin maximum can only import 2M SQL file, if too General Assembly cause cannot import success, but my SQL file has 17M ah ~~~~~~~~~

  No way, can only split the SQL file, beginner python, so when the practice, with Python wrote a split SQL file script:   #由于导出的sql文件总共95张表, each table has this character----------- ----------------------------, so with this character as a criterion, will write every 10 tables to a file, so that a single file import can!!   #以下是python代码 #!/usr/bin/python3.3import re def main ():    #先得到要分割的文件的起始和结束位置所在行数并放入列表x中     count,total,j,l = 0, 0, 0, 0    x = [0,]    fin = open (' Cdu.sql ', ' R ')     for line in fin:        Total + = 1        if Re.search ('-------* ', line):                         #以此判断表的数量             Count + = 1            if count% = = 0:                 & nbsp               #每到10张表时将分割的行数写入x列表中               &NBSP ; #print (count,total)                 X.append (Total)      X.append (len (Open (' Cdu.sql '). ReadLines ()) +1)   #将最后一行也放入x中         For I in x:        print (i,end = ")             print () &nbs P       cnt=1    #读取x中的行数, start and End locations copy the contents of the file to a new file     for i,j in enumerate (' Cdu.sql ', ' R ')):        If i<=x[cnt]:            with open ('%dcdu.sql ' %cnt, ' A + ') as F:                              & nbsp           F.write (j)         else:            CN t+=1            print ("Wirte file" +str (CNT))     print ("OK") if __name__== ' __main_ _ ': Main ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.