I am very new to mysql. I made server from amazon lightsail, linux wordpress instance. I know how to connect localhost mysql, so I tried same way.

import pymysql
connetion = pymysql.connect(host='xxx.xxx.xxx.xxx',
                         port = 80
c =connetion.cursor()
c.execute("SELECT * FROM 'wp_db7_forms'")
result = c.fetchall()

for host, tried my server public IP, localhost:3306(written in wp-copfig.php),

for port, tried 80 , 8080, 3306

for user and password, tried user, password from wp-config.php and my id and pw from phpmyadmin(which set host as *)

but what I only get is this error

pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

wp_db7_froms have only one row, so I don't think error occur because of data amount.

I even tried from sshtunnel import SSHTunnelForwarder but not worked

how can I connect to remote server wordpress mysql? I just need to read db table.

because my app need to check db before work.


Try to connect from some visual tool like MySQL Workbench, use parameters that lightsail provided to you. Also this tutorial might help https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-connecting-to-your-mysql-database. After success connection you will understand what parameters should be used in pymysql.connect.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.