5초 마다 데이터를 insert하는 테스트를 위해 python을 mysql과 연동해 보겠다!
$ pip3 install pymysql
설치가 완료되면 파이썬 파일을 작성한다
📃 insert_data.py
import pymysql.cursors
# connection 정보
conn = pymysql.connect(
host = '', # host name
user = '', # user name
password = '', # password
db = '', # db name
charset = 'utf8'
)
curs = conn.cursors()
sql = "insert into sound(class,eventdate,sound_userIdx) values('motor',default,1);"
curs.execute(sql)
📃 insert_data.py
import pymysql.cursors
import threading
import time
def insert_data():
print('hihi')
# connection 정보
conn = pymysql.connect(
host = 'soundee-db-instance.cigpqobh4owg.ap-northeast-2.rds.amazonaws.com', # host name
user = 'admin', # user name
password = 'soundeedatabase', # password
db = 'soundee', # db name
charset = 'utf8'
)
curs = conn.cursor()
sql = "insert into sound(class,eventdate,sound_userIdx) values('motor',default,1);"
curs.execute(sql)
conn.commit()
threading.Timer(5,insert_data).start()
insert_data()