꿈을 향해 on my way
Connect MySQL database with Python 본문
1. Import libraries
import mysql.connector
import pandas as pd
If you don’t have mysql.connector, go here / if you don’t have pandas, go here
2. Create a connection
cnt = mysql.connector.connect(
host="datawarehouse.brightpowerinc.com",
user= "jpark", # your dbeaver id
passwd= "legendaryfob" # your dbeaver password
)
*Credentials (e.g. DBeaver username and password) are sensitive information and should be stored securely. Managing credentials in environment variable is highly recommended. If you are not familiar with environmental variable, Using .env Files for Environment Variables in Python Applications.
3. Write a query
example_query = (
'''
SELECT *
FROM babl_expansion.cube_bill cb
LIMIT 5
'''
)
4. Read the query with pandas dataframe
df = pd.read_sql_query(example_query, cnt)
beautiful
beautiful
'데이터 사이언스 공부' 카테고리의 다른 글
Pandas - json_normalize 문제 총 정리 (0) | 2022.04.02 |
---|---|
복잡한 JSON 파일 쉽게 처리하기 - 파이썬 (How to flatten complex JSON file in Python) (0) | 2022.04.02 |
Webhook vs API 차이 (0) | 2022.01.26 |
Using .env Files for Environment Variables in Python Applications (0) | 2021.12.22 |
초간단 웹 스크레이핑 / 웹 크롤링 (크롬 익스텐션 - Web Scraper) (2) | 2020.09.09 |
Comments