This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Query a public sql server from within python

I'm trying to query a public sql server from within a python script.

The equivalent terminal command is :

mysql --user=genome -N --host=genome-mysql.cse.ucsc.edu -A -D hg19 -e "select name,name2 from refGene"

On the python script i'm trying to mimic this command with the following code:

import mysql.connector  
db = mysql.connector.connect(host="genome-mysql.cse.ucsc.edu", user="genome", database="hg19")  
cursor = db.cursor()  
data = cursor.execute("select name,name2 from refGene")

Problem is I get that

data = None

I'm quite convinced it has to do something with the flags I have left out and I don't know how I can pass these flags - couldn't find any answer to that.

genome

Can you do this as a subprocess/system call (LINK)?

I tried to at first, but it didn't work (I don't remmember the exact backtrace) I can try again if you think that this approach should work

Google "SQLAlchemy ORM ". And these problems should be asked in stackoverflow.

I think ORM is not necessary for a simple query. This question qualifies as a bioinformatics question - it's about programmatically querying UCSC's MySQL database/

0 answers

No answers yet.

Log in to answer this question.