Hi, I’m trying to access the mysql database from our WordPress in Siteground using python. I would like to use the data from that database with another from a different source to generate some reports.
import ssh tunnel
import mysql.connector from mysql.connector
import errorcode
pkeyfilepath = “path to ppk file with private key”
ssh_host = ‘ssh host’
ssh_port = ssh port
ssh_username = ‘ssh user’
ssh_password = ‘ssh password’
sql_hostname = ‘127.0.0.1’
sql_username = ‘sql user’
sql_password = ‘sql pass’
sql_main_database = ‘database name’
sql_port = 3306
server = sshtunnel.SSHTunnelForwarder( (ssh_host, ssh_port),
ssh_username = ssh_username,
ssh_pkey = pkeyfilepath,
ssh_password = ssh_password,
remote_bind_address = (sql_hostname, sql_port))
server.start()
try:
cnx = mysql.connector.connect( host=sql_hostname,
user=sql_username,
password=sql_password,
database=sql_main_database,
connect_timeout=6000 )
print(“connected to:”, cnx.get_server_info)
except mysql.connector.Error as err:
print(err)
else:
cnx.close()
server.stop()
server.close()
The ssh tunnel works however I’m getting this error:
1045 (28000): Access denied for user ‘sql user’@’localhost’ (using password: YES)
Not sure where the mistake is. The sql user and password are what I get when creating a new user in the MySQL Manager in Siteground, and I have already given it access to the database. I’m not sure how to validate that the user and password really have access to the database, I read I could query the mysql.users table but when I go into the phpMyAdmin I can’t find that table, also that I may need to execute “Flush privileges” but I’m not sure where to execute that. Any help is appreciated!
EDIT: fixed code format
View Reddit by readtimez – View Source