Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- function
- count()
- 덴드로그램
- matplotlib
- string
- numpy
- dendrogram
- list
- analizer
- DataAccess
- Python
- 반복문
- append()
- DataFrame
- len()
- 최솟값
- Machine Learning
- sklearn
- pandas
- IN
- 분류 결과표
- elbow method
- hierarchical_clustering
- del
- Dictionary
- data
- nan
- wcss
- insert()
- 최댓값
Archives
- Today
- Total
개발공부
Python MySQL Connector 를 이용해 Delete 하는 방법 본문
import mysql.connector
def get_connection() :
connection = mysql.connector.connect(
host = '호스트이름',
database = 'DB이름',
user = 'USER명',
password = '비밀번호',
)
return connection
try :
# 데이터 Delete
# 1. DB에 연결
connection = get_connection()
# 2. 쿼리문 만들기
query = '''delete from mysql_table
where col = val;'''
# 3. 커서를 가져온다.
cursor = connection.cursor()
# 4. 쿼리문을 커서를 이용해서 실행한다.
cursor.execute(query)
# 5. 커넥션을 커밋해줘야 한다 => 디비에 영구적으로 반영하라는 뜻
connection.commit()
# 6. 자원 해제
cursor.close()
connection.close()
except mysql.connector.Error as e :
cursor.close()
connection.close()
print(e)'Python > Flask' 카테고리의 다른 글
| Postman으로 API 테스트 방법 (0) | 2022.06.20 |
|---|---|
| Python Flask에서 Resource 클래스를 이용한 API 서버 개발 방법 (0) | 2022.06.17 |
| Python MySQL Connector 를 이용해 Update 하는 방법 (0) | 2022.06.17 |
| Python MySQL Connector 를 이용해 Select 하는 방법 (0) | 2022.06.17 |
| Python MySQL Connector 를 이용해 Insert 하는 방법 (0) | 2022.06.17 |