Подключение к MySQL

Базы данных / Подключение к БД

# pip install mysqlclient

import MySQLdb

# Connect to the database
conn = MySQLdb.connect('HostName', 'UserName', 'Password', 'DatabaseName')
cursor = conn.cursor()

# SQL query execution
cursor.execute("SELECT * FROM tablename")

# Get the data
row = cursor.fetchone()
print(row)

# Close the connection
conn.close()