Search code examples
pythonsql-servermysql-connectorconnectormysql-connector-python

Read Sql Table using Connectorx?


I am reading sql tables using connectorX library and saving as csv but facing weird error The code is

import connectorx as cx

MYSQL_READER_HOST = cfg.sql['host']
MYSQL_READER_USERNAME = cfg.sql['user']
MYSQL_READER_PASSWORD = cfg.sql['passwd']
MYSQL_DB_NAME = cfg.sql['db']

tables = ['table1','table2']
for table in tables:               #line 52 of my code
    print(f'\t => \t Storing {table}')
    query = "select /*+ MAX_EXECUTION_TIME(100000000) */ * from "+ table+";"
    
    table = cx.read_sql(f'mysql://{MYSQL_READER_USERNAME}:{MYSQL_READER_PASSWORD}@{MYSQL_READER_HOST}/{MYSQL_DB_NAME}' ,query,partition_num=10)
    table.to_csv(os.path.join(store_dir, table + '.csv'), index=False)

the error I am facing

Fatal Python error: none_dealloc: deallocating None
Python runtime state: initialized

Current thread 0x00003d60 (most recent call first):
  File "C:\Users\LunchON\Desktop\download_script\util_scripts\data_download_connector_x.py", line 52 in <module>

Solution

  • Can you try version >=0.2.4-alpha.4? This issue should has been fixed https://github.com/sfu-db/connector-x/issues/201