Connect MySQL database using Python code example

Connect MySQL database using Python code example

MySql Database

If you are stucked in testing the connectivity with MySql server with Python, here is the solution. In this PoC we will connect with MySQL server using Python code.


User should have MySql compatible connector installed. Must have access to database with valid credentials

Code example

import mysql.connector
mydb = mysql.connect(user = 'database_user', password = 'database_password', port = 'Port_number', host = 'Database_Host', database = 'Database_Name', auth_plugin = 'caching_sh2_password')

#check connectivity
if mydb.is_connected():
	print("Connection success")
	print("Connection fail")

The above code will print “Connection success” if connection succeed else “Connection fail”

Next >> Create JSON from Excel using Python code example

Leave a Reply

Your email address will not be published. Required fields are marked *