46,175 questions
Not able to connect to Azure MySql DB from Google Colab Notebook
Sumit Tiwari
0
Reputation points
Hi I am trying to connect to Azure MySql Database from Google Colab Notebook using below code:
from langchain_community.utilities.sql_database import SQLDatabase
Define database credentials
db_user = "*******"
db_password = "*******"
db_host = "*******.mysql.database.azure.com"
db_name = "*******"
try:
db = SQLDatabase.from_uri(f"mysql+mysqlconnector://{db_user}:{db_password}@{db_host}:3306/{db_name}")
print("Successfully connected to the database.")
print(db.dialect)
print(db.get_usable_table_names())
print(db.table_info)
except Exception as e:
print(f"Failed to connect to the database: {e}")
I am able to connect with database using above code if I run outside Colab Notebook.
I am able to connect the DB from MySQL workbench also.
Community Center Not monitored
Sign in to answer