티스토리 뷰
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import os import sys sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))) import mysql.connector basedir = os.path.dirname(os.path.abspath(__file__)) db = { 'user' : 'root', 'password' : 'root', 'host' : 'localhost', 'port' : '3306', 'database' : 'mariadb' } mysql_con = None #------------------------------------------------------# def query_executor(cursor): sql = "select * from food" cursor.execute(sql,) #------------------------------------------------------# if __name__ == "__main__": print('test') try: mysql_con = mysql.connector.connect(host='localhost', port='3306', database='mariadb', user='root', password='root') mysql_cursor = mysql_con.cursor(dictionary=True) query_executor(mysql_cursor) for row in mysql_cursor: print('price is: '+str(row['price'])) mysql_cursor.close() except Exception as e: print(e.message) finally: if mysql_con is not None: mysql_con.close() | cs |
'5. 파이썬' 카테고리의 다른 글
머신러닝/--/텔아비브/ 타이타닉 titanic.py (0) | 2020.10.24 |
---|---|
머신러닝/--// Titanic user_dto.py (0) | 2020.10.21 |
파이썬/퍼셉트론-아달린/하마/ perceptron.py (0) | 2020.10.05 |
REST API, Database Connection, os.path.dirname(__file__) (0) | 2020.10.05 |
머신러닝/--/하마/ 타이타닉 컬럼 (Feature) (0) | 2020.09.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Django
- Mlearn
- JUnit
- mariadb
- springMVC
- Oracle
- maven
- database
- vscode
- tensorflow
- SpringBoot
- docker
- ERD
- React
- COLAB
- KAFKA
- AWS
- terms
- jQuery
- Eclipse
- Java
- intellij
- Git
- JPA
- SQLAlchemy
- FLASK
- nodejs
- Algorithm
- Python
- Mongo
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 28 |
29 | 30 | 31 |
글 보관함