0

My problem occurred as follows:

I use the APIs of mysqldb , the codes like this:

 conn = MySQLdb.connect(host='192.168.1.16', user='henry', passwd='password', db='test', charset='utf8')
 cur = conn.cursor()

It is ok, the connect mysql is a success, and it works as well with this:

select count(*) from songs;   everthing is allright.

But if I use sql like this:

select * from songs;

The error is:

connect mysqldb error. the songs table has 5000000 rows.
1
  • You are not really showing the Python code you are using for the sql. Show the code and keep your comments out of the code block. Commented Jun 9, 2013 at 3:16

2 Answers 2

1

MySQLdb save all rows and columns of the select statement in the memory, in your case is 5M rows * n columns, so the error may be caused by two reason:
1. the result is too large to be saved in memory.
2. the result is too large to be transferred via the network connection.

You may try to just return a few rows, not all of them. If you really want to retrieve the entire table, complete it in several times.

Sign up to request clarification or add additional context in comments.

Comments

0

James Bear is correct that you are probably running out of memory. You should use a cursor so that you only load the data you need when you need it.

You can put cursorclass=MySQLdb.cursors.SSCursor in the connect function, and that should fix the problem.

See How to efficiently use MySQLDB SScursor?.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.