CREATE TABLE daily_new (
date date,
cust_bal int(20) NOT NULL,
cust_credit int(20) NOT NULL,
fund_stock int(20) NOT NULL,
fund_hyb int(20) NOT NULL,
fund_bond int(20) NOT NULL,
PRIMARY KEY (date)
);
(1364, u"Field 'cust_credit' doesn't have a default value
에러 떠서
ALTER TABLE daily_test MODIFY COLUMN cust_credit int(20) NOT NULL DEFAULT '0'
다돌리는중
ALTER TABLE daily_test MODIFY COLUMN date date NOT NULL DEFAULT '0000-00-00'
CREATE TABLE [대상 테이블명] SELECT * FROM [원본 테이블명]
테이블을 복사햇다
truncate test1;
그다음 테이블 목차만 남기고 싹 지움
alter table test1 drop kosdaq;
data=open('naver_loan_output.csv')
reader= csv.reader(data)
col1=[]
col2=[]
col3=[]
col4=[]
col5=[]
col6=[]
for line in reader:
col1.append(line[0])
col2.append(line[1])
col3.append(line[2])
col4.append(line[3])
col5.append(line[4])
col6.append(line[5])
def test_2():
for i in range(1,len(col2)):
sql="INSERT INTO test1 (date, cust_bal) VALUES(" + "'" + col1[i]+ "'"+"," + col2[i] + ")"
print sql
cursor.execute(sql)
conn.commit()
conn.close()
됏다 ㅎ
import pymysql
import csv
csv_data= csv.reader(file('naver_loan_output.csv'))
conn=pymysql.connect("localhost", "root","9999","finance")
cursor=conn.cursor()
data=open('naver_loan_output.csv')
reader= csv.reader(data)
col1=[]
col2=[]
col3=[]
col4=[]
col5=[]
col6=[]
for line in reader:
col1.append(line[0])
col2.append(line[1])
col3.append(line[2])
col4.append(line[3])
col5.append(line[4])
col6.append(line[5])
def insert_func():
for i in range(1,len(col2)):
sql="INSERT INTO test1 (date, cust_bal, cust_credit, fund_stock, fund_hyb, fund_bond) VALUES(" + "'" + col1[i]+ "'"+"," + col2[i] +","+col3[i]+","+col4[i]+","+col5[i]+","+col6[i]+")"
print sql
cursor.execute(sql)
conn.commit()
conn.close()
insert_func()
'OLD개발이야기 > Python-mysql' 카테고리의 다른 글
python-mysql 엑셀 읽기, sql 에 업데이트 하기,( 컬럼별 ) (0) | 2017.03.09 |
---|---|
find null and replace -mysql (0) | 2017.03.09 |
Java 설치 (0) | 2017.02.21 |
ubuntu - python - mysql 우분투에서 mysql 접속, 서버접속, 파이썬 디비 연결 (0) | 2017.02.12 |
python - mysql (0) | 2017.02.09 |