Updated on 2025-10-23 GMT+08:00

pymysql.connect()

Description

This method creates a database session and returns a new connection object.

Prototype

conn=pymysql.connect(database="databasename",user="username",password="********",host="127.0.0.1",port=portnum)

Parameters

Table 1 pymysql.connect

Keyword

Description

database

Database name.

user

Username.

password

Password.

host

IP address of the database.

port

Connection port number.

ssl_disabled

Specifies whether to enable SSL on the client. The default value is None.

ssl_ca

Client CA root certificate, which is used for SSL connection.

ssl_cert

Path of the client certificate, which is used for SSL connection.

ssl_key

Path of the client key, which is used for SSL connection.

charset

Encoding format of the client.

autocommit

Autocommit mode. The default value is False.

Return Value

Connection object (for connecting to a database instance)

Examples

For details, see Examples: Common Operations.