1. Create table on my_schema database
2.
데이터 삽입(INSERT)
- Cursor Object 가져오기: cursor = db.cursor()
- SQL 실행하기: cursor.execute(SQL)
- 실행 mysql 서버에 확정 반영하기: db.commit()
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
tumbler = xlrd.open_workbook("data/Tumbler_Factory_revision.xlsx")
sheet = tumbler.sheet_by_name("ANALYSIS")
database = MySQLdb.connect (host="localhost", user="root", password="비밀번호", db="schema이름")
cursor = database.cursor()
query = """INSERT INTO tumbler_table (id, LINE_ID, EQP_ID, TARGET_DATE, BUSY, IDLE) VALUES (%s, %s, %s, %s, %s, %s)"""
id = r
values = (id, LINE_ID, EQP_ID, TARGET_DATE, BUSY, IDLE)
cursor.execute(query, values)
cursor.close()
database.close()
|
Excel data
3. Import excel file data into Mysql
Reference
http://pythonstudy.xyz/python/article/202-MySQL-%EC%BF%BC%EB%A6%AC
https://www.fun-coding.org/mysql_basic6.html
https://www.youtube.com/watch?v=51F_frStZCQ
'DB > MySQL' 카테고리의 다른 글
참조키 설정 오류(Cannot add or update a child row) (0) | 2020.05.11 |
---|