![見出し画像](https://assets.st-note.com/production/uploads/images/119947595/rectangle_large_type_2_63246104b581125d959e93d88f32cfdc.png?width=800)
Photo by
take_kuroki
Python環境でのMySQL
ライブラリのインストール
sudo apt-get install python3-dev default-libmysqlclient-dev
pip install mysqlclient
SQLの実行
import MySQLdb
# MySQLに接続
conn = MySQLdb.connect(
user=user_name,
passwd=user_password,
host=server,
port=port,
db=db_name)
cur = conn.cursor()
# SQL実行
sql = "select 1"
cur.execute(sql)
rows = cur.fetchall()
for row in rows:
id = row[0]
cur.close()
conn.close