Python 2.x MysqlDB module, pythonmysqldb
MySQLdb is an interface for mysql connection. We can connect MySQLdb in python to perform various data operations.
The methods for connecting python to mysql include oursql, PyMySQL, myconyy, and MySQL Connector. However, this article is about another class library MySQLdb, and MySQLdb is the interface for connecting Python to Mysql database, it implements the Python database API Specification V2.0, which is based on MySQL c api. Can be obtained and installed from: https://pypi.python.org/pypi/MySQL-python, and many releases of the linux source has this module, can be directly installed through the source.
I. Database Connection
MySQLdb provides the connect method to establish a connection with the database. It receives several parameters and returns the connection object:
Copy the Code as follows: conn = MySQLdb. connect (host = "localhost", user = "root", passwd = "jb51", db = "test", charset = "utf8 ")
Common parameters include:
Host: specifies the Database host name. The local host is used by default.
User: Database login name. The default value is the current user.
Passwd: Password for database login. Empty by default
Db: name of the database to be used. No default value exists.
Port: the TCP port used by the MySQL service. The default value is 3306.
Charset: Database Encoding