분류
-
Python MySQL: with OPEN_DB 만들기컴퓨터/MySQL 2020. 12. 15. 10:35
commit은 항상 하고, cursor를 주로 사용하기 때문에 알아서 close 시키는 with문을 만들고 싶었다. custom with문 만들기 import os from contextlib import contextmanager @contextmanager def OPEN_DB(): # connect to my local MySQL instance using connection string db = mysql.connector.connect( host="localhost", user=os.environ["MYSQL_USER"], password=os.environ["MYSQL_PASSWORD"], database="mydb", charset="utf8", ) cursor = db.cursor(buff..
-
Python MySQL: 중복 row 인지 확인하기컴퓨터/MySQL 2020. 12. 15. 10:30
위와 같이 id, title, ...로 이루어진 row들이 있는 데이터베이스가 있다. id는 primary key이고, id를 INSERT하기 전에 중복인지 확인하고 싶었다. db 초기화 import mysql.connector db = mysql.connector.connect( host="localhost", user=os.environ["MYSQL_USER"], password=os.environ["MYSQL_PASSWORD"], database="mydb", charset="utf8", ) cursor = db.cursor(buffered=True) 중복 row 체크 왜 빠를까? 만약 id가 기본 키라면 인덱싱이 된다. 인덱스 스캔은 테이블 스캔보다 빠르니까 크기에 관계없이 동일한 성능을 보여준다..
-
MySQL 서비스가 로컬 컴퓨터에서 시작했다가 중지되었습니다.컴퓨터/MySQL 2020. 12. 15. 10:23
모르고 시작 메뉴에서 MySQL을 제거하고 재부팅했더니, 서비스도 안 보이고 MySQL 시작도 안됐다. MySQL 서비스 등록하는 방법 cmd를 관리자 권한으로 실행 mysqld --install MySQL 초기화하기 cmd를 관리자 권한으로 실행 mysqld --initialize --console ※ db와 비밀번호가 초기화되어버린다. ※ 꼭 console 옵션을 붙여서, 임시 비밀번호를 확인한다. MySQL 서비스 실행하기 net start mysql 테스트하기 -p 옵션으로 비밀번호를 입력 후 접속하도록 한다. 비밀번호엔 초기화해서 받은 임시 비밀번호를 사용한다. mysql -uroot -p
-
Python: MySQL 사용하기컴퓨터/MySQL 2020. 12. 14. 16:00
MySQL MySQL Over 2000 ISVs, OEMs, and VARs rely on MySQL as their products' embedded database to make their applications, hardware and appliances more competitive, bring them to market faster, and lower their cost of goods sold. www.mysql.com 할 것 MySQL 서버 실행 Python용 MySQL connector db 만들고 간단하게 table CREATE, SELECT 설치 MySQL 다운로드 dev.mysql.com/downloads/mysql/ Windows 10 my.ini 경로: C:\ProgramData\..
-
Python rich: Console 출력 색깔, 꾸미기컴퓨터/파이썬 2020. 12. 13. 13:10
rich rich Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal pypi.org 1. 소개 rich-console은 python으로 powershell이나 cmd 출력 창을 꾸미는 라이브러리이다. 설치 pip install rich 2. 예제 API 문서 링크: @링크 dictionary, 함수 local value 출력 from rich.console import Console data = [ { "jsonrpc": "2.0", "method": "sum", "params": [None, 1, 2, 4, False, True], "id": "1", }, {"jsonrpc": "2..
-
Python: with문 만들어 사용하기컴퓨터/파이썬 2020. 12. 11. 10:13
with contextlib — Utilities for with-statement contexts — Python 3.9.1 documentation Most context managers are written in a way that means they can only be used effectively in a with statement once. These single use context managers must be created afresh each time they’re used - attempting to use them a second time will trigger an excep docs.python.org 1. with문 파이썬에서는 with문을 이용해서 외부 리소스를 간편히 이용..
-
Kafdrop: Kafka 웹 UI컴퓨터/Kafka 2020. 12. 4. 16:45
Kafdrop obsidiandynamics/kafdrop Kafka Web UI github.com 1. 소개 kafdrop은 Kafka 토픽, 브로커, 컨슈머 그룹 등 Kafka을 웹 UI로 볼 수 있게 해주는 java 프로그램이다. 2. 사용법 JDK 11+, Kafka 0.11.0+ 또는 Azure Event Hubs 필요 Kafka서버만 실행해도 작동함 다운로드: github.com/obsidiandynamics/kafdrop/releases Releases · obsidiandynamics/kafdrop Kafka Web UI github.com "Download from Bintray"에서 .jar 파일만 다운로드한다. jar이 있는 폴더에서 다음을 실행한다. (brokerConnect를 설..
-
Kafka Slack API Producer 만들기 (Python)컴퓨터/Kafka 2020. 12. 3. 15:56
Kafka 예제 프로젝트 Apache Kafka A Distributed Streaming Platform. kafka.apache.org 이전 글: Kafka Slack API Consumer 만들기 1. 소개 이 예제에서 만들 결과물은 다음과 같다. Producer를 통해 이전 글(Consumer)에게, 매 5초마다 Slack 채널 "일반"에서 메시지를 읽고, 누군가 글을 남겼는데 "bug"란 단어를 포함한 글이면, json으로 dump 시켜서 Consumer에게 전송한다. {"USER": "ikr", "TEXT": "I found a bug, where I can copy my items over and over."} 그러면, Consumer는 자동으로 USER과 TEXT를 읽어서, 내가 원하는 S..