Open Dominik-Majcherczyk opened 18 hours ago
test file which is working perfectly fine:
def test_db_connection():
try:
connection = mysql.connector.connect(
host="172.17.0.1",
port=3306,
user="root",
password="root"
)
if connection.is_connected():
print("Successfully connected to the database!")
# Test querying tables
cursor = connection.cursor()
cursor.execute("SHOW TABLES")
tables = cursor.fetchall()
print("\nTables in database:")
for table in tables:
print(f"- {table[0]}")
except Exception as e:
print(f"Error: {e}")
finally:
if 'cursor' in locals():
cursor.close()
if 'connection' in locals() and connection.is_connected():
connection.close()
print("\nDatabase connection closed.")
if __name__ == "__main__":
test_db_connection()
Yes, if you're running the service in docker and running the test file directly in local python, then the docker networking is probably the issue.
You could validate that by running the service in local python too. See the instructions here.
Hi! I created a minimalist tool that is supposed to connect to my local database (maria db, localhost). The database works - I am able to connect to it from a test file. Unfortunately, inside the application, the tool is unable to find the specific database. Does anyone know what could be the problem? Could it possibly be due to the docker?
minimalist tool: