Connecting to MySQL Server
We can connect to the MySQL server using the connect() method.
Python3
# importing required libraries import mysql.connector dataBase = mysql.connector.connect( host = "localhost" , user = "user" , passwd = "password" ) print (dataBase) # Disconnecting from the server dataBase.close() |
Output:
<mysql.connector.connection_cext.CMySQLConnection object at 0x7f73f0191d00>
Note: For more information, refer to Connect MySQL database using MySQL-Connector Python.
Python MySQL
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.
This Python MySQL tutorial will help to learn how to use MySQL with Python from basics to advance, including all necessary functions and queries explained in detail with the help of good Python MySQL examples. So, let’s get started.