0

I want to connect a MySQL Database from an other Network in Python.

Eg: Network A: Server, Network B: PC

I alerady tried this link but i got an error message: 2003: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx:3306' (10060 Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat)(Its German) The IP is correct but it doesnt work. The XAMPP Port for the Server is 3306 so this isn't the problem and the server is running with the mysql module and the apache module. I already opened the poerts 3306 and 80 with TCP and UDP

on localhost it worked perfect

And thats my code:

import mysql.connector
from mysql.connector import errorcode

# Obtain connection string information from the portal
config = {
  'host':'xxx.xxx.xxx.xxx',
  'user':'coinchaser',
  'password':'Coinchaser2021',
  'database':'coinchaser'
}

# Construct connection string
try:
   conn = mysql.connector.connect(**config)
   print("Connection established")
except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with the user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exist")
  else:
    print(err)
else:
  cursor = conn.cursor()

  # Insert some data into table
  cursor.execute("INSERT INTO leaderboard (crdate, playername, points, playedTime) VALUES (%s,%s,%s,%s)", ("16.03.", "test1", 400, "1:45.65"))

  # Cleanup
  conn.commit()
  cursor.close()
  conn.close()
  print("Done.")
chraebsli
  • 184
  • 12

0 Answers0