Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-17-2004, 07:50 PM   #1
Registered: Jun 2003
Location: West Grove, PA
Distribution: Gentoo, Debian, SuSE, Mandrake
Posts: 55

Rep: Reputation: 15
How to read a single sequential record from MySQL?

I'm writing an application in MySQL and Python that must display several thousand records from a database. I wanted to use the MySQL "SELECT" command to select the records I want to see, and then use the "ORDER BY" directive to retrieve them in the correct order. But my python program will read in the entire select set into an array which may grow too large to process properly. Ideally, I want to retrieve a single record, display it, then retrieve the next record.

Can somebody suggest the MySQL command that will retrieve a single record in a sequence, and allow for then retrieving the next record?
Old 11-17-2004, 11:08 PM   #2
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You need to setup a database cursor to fetch one row at a time.

I don't know python, but I'll take a stab at an example:
db = MySQLdb.connect(...)
cursor = db.cursor();
cursor.execute ( "Select first_name, last_name from user")
while (1):
  row = cursor.fetchone()
  if row == None:
  print row[0] row[1]


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read a single key? kornerr Programming 5 11-01-2005 12:07 PM
Finding the last record on a MySQL table? AQG Linux - Software 5 07-13-2005 01:55 PM
Read write privileges for single user... Slyder42 SUSE / openSUSE 4 11-24-2004 07:20 PM
editing read-only files in single user mode cmiwebmaster Linux - Newbie 3 04-14-2003 08:15 PM
select the last x record added into mysql meluser Programming 3 04-14-2003 04:37 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration