How to establish a connection by executing python source code

Before entering to this point , we must sure that our system have python.
So in command prompt I typed python –version, then I got python 3.8.5
Then we have to install mysql-connector module.
So in command prompt we type mysql-connector-python then enter, now the module will successfully install.


https://silantutorial.com/tutorial/python/connection-by-executing-python-source-code.php

Now we will go to our environment, here I have used Atom IDE. Let’s see the following
source code:

img

Output:

img

Explanation :  Here first I imported mysql.connector module then there is a built in function named as connector() coming from mysql.connector module, taking three arguments like host, user, and password value. host=’localhost’ ; this localhost is the MySQL server name, default user name is root and password value what ever you have given that password value you specify. When connector() is invoking by mysql.connector then it is returning a variable(let mydb here) and that variable represents establishment of connection or connectivity.


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc




 PreviousNext