Query a public sql server from within python
0
0
Entering edit mode
4.3 years ago

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 • 940 views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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/

ADD REPLY

Login before adding your answer.

Traffic: 1886 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6