Summary
This hour you learned how to incorporate open-source databases in your Python scripts. The
Raspberry Pi supports both the MySQL and PostgreSQL open-source database servers, and you can
use them for storing and retrieving data in your scripts.
First, you learned how to install the MySQL database server, how to set it up, and how to use the
MySQL/Connector Python module to interact with the database in your Python scripts. Next, you
saw how to install and set up the PostgreSQL database server and how to use the psycopg2 module
to interact with it in your Python scripts. Both systems provide advanced data storage and retrieval
methods to add great functionality to your Python scripts.
In the next hour, we’ll take a look at another popular aspect of programming—Web programming. The
Raspberry Pi provides some modules to help you publish your Python programs on the Web.
Q&A
Q. Is the Raspberry Pi really powerful enough to support a full-blown database server such
as MySQL or PostgreSQL?
A. Yes, you can run the MySQL and PostgreSQL database servers on the Raspberry Pi just fine. I
wouldn’t recommend trying to support thousands of application users at the same time, but for
a small number of concurrent users, Raspberry Pi will hold out just fine!
Q. Which database server is better, MySQL or PostgreSQL?
A. This has been a longstanding debate in the open-source database world. The general
consensus is that the MySQL database server is usually faster, but the PostgreSQL database
supports more advanced database features. Which one you decide to use depends on the
database requirements for your specific application.
Workshop
Quiz
1. What data storage method allows you to easily store application data and retrieve it later,
using different Python scripts?
a. Variables
b. Relational databases
c. Library modules
d. Log files
2. Using standard files to store and retrieve data is just as easy as using a relational database
server. True or false?
3. When method from the psycopg2 module should you use to retrieve the data records from a
SELECT query?
Answers
1. a. relational databases. Database servers that use relational databases can quickly store and
retrieve data behind the scenes, without you having to do much coding.