What Beginners Ask Online About Installing Database Drivers

Before your program can talk to a database, it needs a driver: a library that knows how to speak that database's language. Installing one is where many beginners get stuck. These are the questions that come up most, with direct answers.

"What is a driver, exactly?"

A driver is a translator between your programming language and a particular database. Your code calls simple functions such as connect and execute; the driver turns those calls into messages the database understands, and turns the answers back into rows your code can use. Each language has drivers for each database.

LanguageSQLitePostgreSQLMySQL
Pythonsqlite3 (built in)psycopgmysql-connector-python or PyMySQL
Node.jsbetter-sqlite3 or sqlite3pg (node-postgres)mysql2
JavaSQLite JDBC driverPostgreSQL JDBC driverMySQL Connector/J

"Python says ModuleNotFoundError. I installed it!"

Usually the package was installed into a different Python than the one running your script. Fixes:

python -m pip install psycopg[binary]
python your_script.py

Using python -m pip makes sure pip installs into the same Python you run. If you use a virtual environment, activate it first, then install.

"Do I need to install anything for SQLite in Python?"

No. The sqlite3 module comes with Python. You can start with import sqlite3 straight away.

"npm install worked, but require fails."

Check you installed the package in the same project folder where your code lives, and that the package name matches exactly: pg, not postgres. Run npm ls pg to see whether it is installed in that project.

"Which package should I choose? There are several."

Pick the one the official documentation of your database or framework recommends, or the one used in the tutorial you are following. For beginners, consistency with your learning material matters more than small differences between packages.

"It installs but connecting fails."

Installing the driver and connecting are two different steps. Connection errors usually mean:

Our reader questions about connection errors go through these one by one.

"Installation fails with compiler errors."

Some drivers include parts written in C that need building. Many offer a ready-built version instead. For psycopg, the psycopg[binary] package is the ready-built option intended for getting started. Check the driver's installation page for your operating system.

"Do I need an ORM as well?"

No. A driver alone is enough to run SQL. An ORM is an extra layer that sits on top of a driver. Learning with the driver first makes it much clearer what the ORM is doing later.

A tiny test once it works

import sqlite3
conn = sqlite3.connect(":memory:")
print(conn.execute("SELECT 1 + 1").fetchone())   # (2,)

If you see (2,), your driver works and you are ready to go.

A free learning page for beginners. Practise on a test database, never on real customer data, and check the official documentation for your database version.

This is a static page of sample discussion topics. There is no live forum, membership or user community on this site.

Related pages on this site