1

I am new to Python. I am trying to implement control of two blowers, for cooling an enclosed space, in a Raspberry Pi running Python 2.7 and MySQLdb. I want to store 21 columns of data at 1 row every 5 minutes for 48 hours. After the 48 hours, each time a new row is added, the oldest row will be deleted placing a finite limit on the size of the database. The purpose of the database is to be able to look at the system performance over the past two days and use the data for system monitoring and optimization. As, I hope to have this system running for years, I am concerned that the Raspberry Pi's non-volatile SD card storage will begin to fail from the high amount of rewrites. I am not concerned about data security. I am looking for a solution where the data table is stored in ram to prevent SD card premature failure and because if the data is lost do to something like a power outage when the system is rebooted the database would be refilled with new data over the next two days. I am hoping someone can point me in the right direction for writing a database with the table stored in ram.

DougS
  • 21
  • 2
  • Welcome to Stackoverflow. You will receive more responses if you show us what you have already done so far. The more specific your questions are, the better. – Tammo Heeren Oct 23 '16 at 18:42

2 Answers2

1

Rather than MySQL, you should use sqlite, which comes with Python and has an option to create an in-memory database.

Or, if it's just key-value pairs you're storing, Redis would be an even better fit.

Generally though, if you're worried about the SD card failing, why not buy a small external HD and connect it to the pi?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

If you really want to use memory tables with MySQL, you should look at How do I make a MySQL database run completely in memory?

Another solution would be to create a filesystem in memory. I found there an article you could study. In essence, it recommends to use tmpfs and then locate the table on it.

Is there a particular reason why would like to go the hard route, instead of using a plain Python structure or a SQLite in-memory database, as Daniel suggested?

Community
  • 1
  • 1
fralau
  • 3,279
  • 3
  • 28
  • 41