Guest User

Untitled

a guest
Apr 18th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import urllib
  2.  
  3. from sqlalchemy import (
  4.     create_engine,
  5.     text,
  6. )
  7.  
  8. connection_string = (
  9.     "DRIVER=MySQL ODBC 8.0 ANSI Driver;"
  10.     "SERVER=localhost;"
  11.     "PORT=3307;"
  12.     "DATABASE=mydb;"
  13.     "UID=scott;"
  14.     "PWD=tiger;"
  15.     "charset=utf8mb4;"
  16. )
  17. params = urllib.parse.quote_plus(connection_string)
  18. connection_uri = f"mysql+pyodbc:///?odbc_connect={params}"
  19. engine = create_engine(connection_uri)
  20. with engine.begin() as conn:
  21.     print(conn.execute(text("SELECT @@VERSION")).scalar())  # 5.6.13
  22.  
Advertisement
Add Comment
Please, Sign In to add comment