Python 读取MySQL大数据表数据

import pymysql

dbmy = pymysql.connect("127.0.0.1","xxx","xxx","xxx",cursorclass = pymysql.cursors.SSDictCursor)

cursor = dbmy.cursor()

sql = "select * from table_name"

relnum = cursor.execute(sql)

result = cursor.fetchone()
i = 0
while result is not None:

    result = cursor.fetchone()
    i = i + 1
    print(i)

cursor.close()
dbmy.close()

数据量很大时有可能需要设置数据库的最大执行时间,临时处理如下:

show variables like '%max_execution_time%';
SET max_execution_time=86400000

set  wait_timeout = 28800;
set global  wait_timeout = 28800;

你可能感兴趣的:(Python)