Not able to connect to Azure MySql DB from Google Colab Notebook

Sumit Tiwari 0 Reputation points
2025-01-19T07:24:47.0766667+00:00

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
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.