Работа с базами данных (БД) / Подключение к БД

# 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()