Python DB – API module is not installed on your machine if you get this error. You can download the MySQL database connector for Python from SourceForge.

Alternatively, you can also download and install Python MySQL connector from their official website – MySQL/Python Connector.

Once you’ve successfully established the Python database connection with the MySQL server, you can now start writing the following Python code to check the database connectivity and perform the basic CRUD operations on the database.

Python Database Connection To MySQL Program

Here’s a sample code to check the version of the MySQL database server that the Python program connects to.