How to connect to a SQL server using Python SQLAlchemy

Опубликовано: 21 Июль 2026
на канале: Raghu Veer Tech
3,168
51

Connect to any SQL Server in 60 seconds using Python with SQL Alchemy!
MySQL connector for python
How to connect to a remote sql server


Import the libraries
import sqlalchemy
from sqlalchemy.sql import text

Create a Mysql database engine

engine = sqlalchemy.create_engine("mysql+mysqlconnector://username:password@localhost:port_number/database_name")

Establish connection to SQL database and execute the query

with engine.connect() as connection:
result = connection.execute(text("sql query"))
for row in result:
print(row)