Search code examples
mysqlpython-3.xpymysql

Select from MySql with a variable


I'm trying to search in a database with python3 with PyMySQL. I want to have a list of ips, that can be put in a database and return that data to the ip address.

But i can't even search for one ip. Is it possible or not ?

ip = "10.0.4.64"
cur_syslog.execute("SELECT data FROM firewall WHERE source_ip = values (%s)",(ip))

Solution

  • Your query is not well written. It should be:

    cur_syslog.execute("SELECT data FROM firewall WHERE source_ip = %s", (ip))