Python Database Tutorial
Python being a high-level language provides support for various databases. We can connect and run queries for a particular database using Python and without writing raw queries in the terminal or shell of that particular database, we just need to have that database installed in our system.
In this tutorial, we will discuss how to Python with the most commonly used relational databases such as MySQL, SQLite, NoSQL databases like MongoDB and we will also discuss how to deal with JSON using Python with the help of good examples.
Python MySQL Connector is a Python driver that helps to integrate Python and MySQL. This Python MySQL library allows the conversion between Python and MySQL data types. MySQL Connector API is implemented using pure Python and does not require any third-party library.
- Install Python MySQL connector
- MySQL-Connector-Python module in Python
- Connect MySQL database using MySQL-Connector Python
Python MySQL Queries
- Python MySQL – Create Database
- Python: MySQL Create Table
- Python MySQL – Insert into Table
- Python MySQL – Select Query
- Python MySQL – Where Clause
- Python MySQL – Order By Clause
- Python MySQL – Delete Query
- Python MySQL – Drop Table
- Python MySQL – Update Query
- Python MySQL – Limit Clause
- Python MySQL – Join
- Commit & RollBack Operation in Python
Note: For more information, refer to our detailed Python MySQL Tutorial
Python SQLite3 module is used to integrate the SQLite database with Python. It is a standardized Python DBI API 2.0 and provides a straightforward and simple-to-use interface for interacting with SQLite databases. There is no need to install this module separately as it comes along with Python after the 2.5x version.
- Introduction to SQLite in Python
- Python SQLite – Connecting to Database
- SQLite Datatypes and its Corresponding Python Types
Python SQLite Queries
- Python SQLite – Cursor Object
- Python SQLite – Create Table
- Python SQLite – Insert Data
- Python SQLite – Select Data from Table
- Python SQLite – WHERE Clause
- Python SQLite – ORDER BY Clause
- Python SQLite – LIMIT Clause
- Python SQLite – JOIN Clause
- Python SQLite – Deleting Data in Table
- Python SQLite – DROP Table
- Python SQLite – Update Data
- Python SQLite – Update Specific Column
Note: For more information, refer to our detailed Python SQLite3 Tutorial
Python JSON – Reading and Writing
- How to Parse Data From JSON into Python?
- How To Convert Python Dictionary To JSON?
- Python – Convert JSON to string
- Ways to convert string to json object
- Convert JSON data Into a Custom Python Object
Python JSON – Serializing and Deserializing
- Serializing JSON in Python
- json.dump() in Python
- json.dumps() in Python
- Python – Difference between json.dump() and json.dumps()
- Deserialize JSON to Object in Python
- json.load() in Python
- json.loads() in Python
- Difference Between json.load() and json.loads()
- Encoding and Decoding Custom Objects in Python-JSON
- Serialize and Deserialize complex JSON in Python
MongoDB is one of the most popular NoSQL database. It is a cross-platform, object-oriented database. Basically NoSQL means MongoDB does not store data in the table or relational format rather provide a different mechanism for storage and retrieval of data. This is called BSON which is similar to JSON. That’s why MongoDB offers high speed, high availability, and high scalability.
- MongoDB and Python
- Guide to Install MongoDB with Python | Windows
- What is a PyMongo Cursor?
- Create a database in MongoDB using Python
Python MongoDB Queries
- What is a MongoDB Query?
- Insert and Update Data Query
- insert_one Query
- insert_many Query
- Difference Between insert, insert_one, and insert_many queries in Pymongo
- Update_one Query
- Update_many Query
- insert, replace_one, replace_many Queries
- Delete Data and Drop Collection
- Delete_one Query
- Delete_many Query
- Find Query
- find_one Query
- find_one_and_update Query
- find_one_and_delete query
- find_one_and_replace Query
- Sort Query
- distinct Query
- rename Query
- bulk_write Query
- $group (aggregation) Operation
- Limit Query
- Nested Queries in PyMongo
Python MongoDB Indexing
- Indexing in MongoDB using Python
- Python MongoDB – create_index Query
- How to create index for MongoDB Collection using Python?
- Get all the information of a Collection’s indexes using PyMongo
- drop_index Query
- How to Drop all the indexes in a Collection using PyMongo?
- How to rebuild all the indexes of a collection using PyMongo?