The Python database interface supports a wide range of databases, so you can choose the one that suits your project.
GadFlymSQL MySQL PostgreSQL Microsoft SQL Server 2000 InformixInterbase Oracle Sybase
Different databases you need to download different DB API modules, for example, you need to access Oracle database and Mysql data, you need to download Oracle and MySQL database module.
The DB-API is a specification. It defines a set of required objects and database access methods in order to provide a consistent access interface to a wide variety of underlying database systems and a wide variety of database interface programs.
Python's DB-API, which implements interfaces to most databases, allows you to connect to databases and manipulate them in the same way.
Python DB-API Usage Flow.
Introducing the API module. Obtaining a connection to the database. Execute SQL statements and stored procedures. Close the database connection.
MySQLdb
MySQLdb is an interface for Python to link Mysql databases , which implements the Python Database API Specification V2.0 , built on the MySQL C API.
mounting
Installation is done directly using pip, and some system dependencies need to be installed before that.
CentOSyum install gcc python-devel mysql-devel zlib-devel openssl-devel
Ubuntusudo apt-get install libmysqlclient-dev libmysqld-dev python-dev python-setuptools
After installing the dependencies, install directly using pip, the MySQLdb module is called MySQL-python on pip.
Knowledge Point Expansion:
Connecting to mysql database using python
Six common connection parameters
- Parameter host: ip of the host where the mysql server is located;
- Parameter user: user name
- Parameter password: password
- Parameter port: port of the connected mysql host, default is 3306
- Parameter db: name of the database to connect to
- Parameter charset: when reading data in Chinese will be garbled, we need to set the encoding; we use python to operate the database, then python is equivalent to the client, we are using this client to operate the mysql server server, python3 default utf8 character set, my mysql server defaults to the latin1 character set, so every table created in mysql is built with utf8 encoding, so the setting here should be the connection connector encoding.
to this article on python connection mysql what methods are introduced to this article, more related python how to connect mysql content please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!