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 ()