Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib
- from sqlalchemy import (
- create_engine,
- text,
- )
- connection_string = (
- "DRIVER=MySQL ODBC 8.0 ANSI Driver;"
- "SERVER=localhost;"
- "PORT=3307;"
- "DATABASE=mydb;"
- "UID=scott;"
- "PWD=tiger;"
- "charset=utf8mb4;"
- )
- params = urllib.parse.quote_plus(connection_string)
- connection_uri = f"mysql+pyodbc:///?odbc_connect={params}"
- engine = create_engine(connection_uri)
- with engine.begin() as conn:
- print(conn.execute(text("SELECT @@VERSION")).scalar()) # 5.6.13
Advertisement
Add Comment
Please, Sign In to add comment