Python database connection mysql | How to Connect Python with MySQL | Connection to MySQL in VS Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys welcome to my Channel today in this video tutorial we are going to learn about connecting to mySQL database in Python so for this purpose we are using myscale database in same so I have started this Apache and this uh MySQL you can see this and now I'll go to this Visual Studio code and uh I'll open Terminal new terminal and here we will use pip install py my SQL now if I press enter so it will take some time and installed uh install this py MySQL now it is uh installed so now I will import this well and now we will write the connection so for connection we need host user password and database name so for that I will create a variable connection here is equal to py mySQL dot connection or dot connect and then we will use host here equals and here we will pass Local Host because if I come to this so we are running this uh mySQL database on localhost if I come to this um Google Chrome let me show you the database so I'll search here localhost and it will go to Zam control panel and now from here I can select this PHP my admin and now from this PHP my admin I'll go to database so this is our database and we I have created this test DB here and now if I expand here this test DB I have this employee table now if I click on this now you can see that I have two records here one is uh 50 Mothership senior developer and the other one is 55 awesome and team lead and this is employer number if my name and employee designation now if I come again to this Visual Studio code so this is our host localhost now I'll pass in the user so for that I will use user equals and here all pass root because we are using the rule to user and then I will pass in the password but we have to only pass p a double s w d is showing us the suggestion equal to and it is empty because we we are not using any password here and then we will uh pass in the database name so here I will use database equals and our database is this DB so now our connection is complete so now I'll create the cursor so cursor equals connection dot cursor and now we will pass in the query so I'll use Query equals now we are selecting data from the employee table so select from employee so we have written our query now we will execute this query with this cursor so now here I will use cursor dot execute and I'll pass in the query and now I'll use now this curse is showing an error so I'll Express this so that it is readily indented now I'll get the rows so rows equals cursor Dot fetch all and now I'll use for Loop so far a row enrolled full colon and now here I will print row and now I'll use a um connection dot commit and connection Dot close and now let's run the application and let's check it if it is working so if I run this now you can see that 50 Mothership senior developer and 55 awesome team lead both are read from this employee table and shown in the terminal here so that's all for today I hope you like the video if you like the video please like subscribe and comment thank you
Info
Channel: Programming Guru
Views: 6,430
Rating: undefined out of 5
Keywords: Python Database Connection, How to Connect Python with MySQL, MySQL and Python, python with mysql, python, sql, mysql, mysql and python, python database connectivity, python connection to mysql, connection to mysql in pyton, connection to mysql in visual studio code, connection to mysql in vscode, mysql and vscode, python master, python for beginners, python tutorial, connection to mysql in vs code, how to connect mysql to visual studio code 2022, vs code and mysql connection
Id: Sxd8rQHCPcA
Channel Id: undefined
Length: 5min 57sec (357 seconds)
Published: Mon Oct 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.