Question: Query a public sql server from within python
0
gravatar for Eliran Turgeman
6 weeks ago by
Eliran Turgeman10 wrote:

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 • 125 views
ADD COMMENTlink modified 6 weeks ago by RamRS30k • written 6 weeks ago by Eliran Turgeman10

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

ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by genomax89k

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 REPLYlink written 6 weeks ago by Eliran Turgeman10

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

ADD REPLYlink modified 6 weeks ago • written 6 weeks ago by shoujun.gu370

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 REPLYlink written 6 weeks ago by RamRS30k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1477 users visited in the last hour