I have mysql on local Ubuntu server with several databases. I have php pages on the local mysql server as well as remote web servers (apache). There is no issue connecting & manipulating data in the mysql databases via the php web pages (mysql accepts connections and port is standard 3306).
I am trying to connect with python3 remotely from the same ubuntu servers. The import mysql.connector command initially failed since the connector was not installed. After I installed it I tested connecting with code from mysqltutorial
import mysql.connector
# Initialize a variable to hold the database connection
conn = None
try:
# Attempt to establish a connection to the MySQL database
conn = mysql.connector.connect(host='192.168.1.1',
port=3306,
database='Tester',
user='theuser',
password='greatpassword')
# Check if the connection is successfully established
if conn.is_connected():
print('Connected to MySQL database')
except mysql.connector.Error as e:
# Print an error message if a connection error occurs
print(e)
finally:
# Close the database connection in the 'finally' block to ensure it happens
if conn is not None and conn.is_connected():
conn.close()
I get the following error
2003: Can't connect to MySQL server on '192.168.1.1:3306' (111 Connection refused)
Every search on that error says I don’t have the mysql.connector installed, but it is. Some results were AWS issues, this is all local.
I can connect to mysql via php on apache, but not with python. Any ideas
The above code from mysqltutorial.org was tried and failed as well as other code from various sites with connection examples.