How to Connecting MySQL Using Connector

BestCloudHostingASP.NET | The connect() constructor creates a connection to the MySQL server and returns a MySQLConnection object.

The following example shows how to connect to the MySQL server:

It is also possible to create connection objects using the connection.MySQLConnection() class:

Both methods, using the connect() constructor, or the class directly, are valid and functionally equal, but using connector() is preferred and is used in most examples in this manual.

To handle connection errors, use the try statement and catch all errors using the errors.Error exception:

 If you have lots of connection arguments, it’s best to keep them in a dictionary and use the ** operator:  

Using the Connector/Python C Extension

As of Connector/Python 2.1.1, the use_pure connection argument determines whether to connect using a pure Python interface to MySQL, or a C Extension that uses the MySQL C client library (. The default is True (use the pure Python implementation). Setting use_pure to False causes the connection to use the C Extension if your Connector/Python installation includes it. The following examples are similar to others shown previously but with the includion of use_pure=False.

Connect by naming arguments in the connect() call:

 Connect using an argument dictionary:  

It is also possible to use the C Extension directly, by importing the _mysql_connector module rather than the mysql.connector module

How to Connecting MySQL Using Connector
Rate this post