cancel
Showing results for 
Search instead for 
Did you mean: 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to construct the sql url as the password is having special characters.

User16753724663
Valued Contributor

while using the sqlalchemy, unable to connect with sql server from databricks:

user='user@host.mysql.database.azure.com'
password='P@test'
host="host.mysql.database.azure.com"
database = "db"
connect_args={'ssl':{'fake_flag_to_enable_tls': True}}
connect_string = 'mysql+pymysql://{}:{}@{}/{}'.format(user,password,host,database)
     
engine = create_engine(connect_string, connect_args=connect_args, echo=False)
map = pd.read_sql("SELECT * FROM rig_emissions.tag_lookup", engine)
map['key'] = map['rig'].astype(str)+map['tagpath']
 
mapDict = dict(zip(map.key,map.id))
 

It returns the below error:

(pymysql.err.OperationalError) (2003, 'Can't connect to MySQL server on 'P@test' ([Errno -2] Name or service not known)')

1 REPLY 1

User16753724663
Valued Contributor

We can use urllib.parse to handle special characters. Here is an example:

import urllib.parse
user='user@host.mysql.database.azure.com'
 
password=urllib.parse.quote_plus("P@test")
host="host.mysql.database.azure.com"
database = "db"
 
connect_args={'ssl':{'fake_flag_to_enable_tls': True}}
 
connect_string = 'mysql+pymysql://{}:{}@{}/{}'.format(user,password,host,database)
 
 
engine = create_engine(connect_string, connect_args=connect_args, echo=False)
 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!