read frame with sqlalchemy, mysql and pandas

前端 未结 3 1630
情深已故
情深已故 2020-12-31 14:39

I am trying to connect to a mysql database, works fine with Option 1:

from sqlalchemy import create_engine
engine = create_engine(\'mysql://root:root@localho         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 15:29

    You need to have a raw database connection, and not an instance of Connection. In order to get it call either engine.raw_connection() or engine.connect().connection:

    from pandas.io import sql
    #cnx = engine.connect().connection # option-1
    cnx = engine.raw_connection() # option-2
    xx = sql.read_frame("SELECT * FROM user", cnx)
    cnx.close()
    

提交回复
热议问题