How to connect to PostgreSQL using Python script

In this article, we will see how to connect to PostgreSQL Server using Python script. To connect to PostgreSQL Server from Python, we have to install psycopg2 on Linux or Windows.

Steps to connect to PostgreSQL using Python:

Continue reading How to connect to PostgreSQL using Python script

ModuleNotFoundError: No module named ‘psycopg2’

psycopg2 module is used to connect to PostgreSQL Server using Python. But, if you receive below error means,you have not installed psycopg2 module.

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'psycopg2'

Solution:

Continue reading ModuleNotFoundError: No module named ‘psycopg2’

How to connect to MySQL using Python on Linux

In this article, we will see how to connect to MySQL using Python on Linux.In this article, we will connect to MySQL Server from python using mysql-connector. Connect to Python contains below steps.

1. Install mysql connector.
2. Create connection variable in python script file.
3. Execute command on MySQL Server using python script file.

Connection to MySQL using Python Steps:

Step1: Install mysql connector.
Continue reading How to connect to MySQL using Python on Linux

How to connect to MySQL using Python on Windows

In this article, we will see how to connect to MySQL using Python on Windows. In this article, we will connect to MySQL Server from python using mysql-connector. Connect to Python contains below steps.

1. Install mysql connector.
2. Create connection variable in python script file.
3. Execute command on MySQL Server using python script file.

Connection to MySQL using Python Steps:

Step1: Install mysql connector.
Continue reading How to connect to MySQL using Python on Windows

MongoDB exception: connect failed

When tried to connect to MongoDB server, recieved the error: “MongoDB exception: connect failed”. This error occurs if MongoDB server is offline or It may be connecting with default port 27017.

MongoDB shell version v4.0.10 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb 2019-07-09T22:18:34.660-0700 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:344:17 @(connect):2:6 exception: connect failed

Reason:

Possible reason check the MongoDB server is up and running fine or not. In my case this error came because MongoDB server is down.

MongoDB exception connect failed

Solution 1:
Continue reading MongoDB exception: connect failed