How to use MySQL with Anaconda's Python IDE

后端 未结 2 646
野的像风
野的像风 2021-01-12 23:01

I just want to be able to do a simple SELECT * FROM query.

I found a Python MySQLdb Package, but can\'t get it to install using the Windows

2条回答
  •  无人共我
    2021-01-12 23:18

    Anaconda comes with the conda installer, so use conda instead of pip. This works for all packages that are available for conda. There are MySQL packages available, you can select them from https://docs.continuum.io/anaconda/pkg-docs.

    For pymysql you open up the command line, call 'conda install pymysql' and watch the magic unfold.

    There is of course a trade-off (for the not-gurus like me at least): there are also packages that are not available for conda. tweepy is one of those. On the other hand, I did not manage to get sklearn installed using pip after uninstalling anaconda as suggested in the other answer.

    [Edit:]I could install tweepy after searching on https://anaconda.org

    [Edit, in response on question:] @scottlittle,you mean something like:

    # -*- coding: utf-8 -*-  
    # imports  
    import pymysql  
    
    # open connection to the database  
    conn = pymysql.connect(host='localhost',  
                           port=3306,  
                           user='',  
                           passwd='',  
                           db='',  
                           charset='utf8')  
    cur = conn.cursor()  
    
    sql = "SELECT * FROM "  
    cur.execute(sql)  
    
    # close connection to the database  
    cur.close()  
    conn.close(  )
    

提交回复
热议问题