<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>python mysql Archives -</title>
	<atom:link href="https://mitindia.in/tag/python-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/python-mysql/</link>
	<description></description>
	<lastBuildDate>Thu, 31 Dec 2020 06:24:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>python mysql Archives -</title>
	<link>https://mitindia.in/tag/python-mysql/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Python and MySQL</title>
		<link>https://mitindia.in/python-and-mysql/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Thu, 31 Dec 2020 06:10:50 +0000</pubDate>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[data science]]></category>
		<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python mysql]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=1098</guid>

					<description><![CDATA[<p>Database connectivity using Python In this article we&#8217;ll be covering all database examples like SELECT, INSERT, UPDATE and DELETE operations using Python and MySQL database. First,, create database[college_db] and table[student_info] as per following image and insert few records  [here we using wamp server]  before you execute all programs in Python. a) SELECT operation # pip [&#8230;]</p>
<p>The post <a href="https://mitindia.in/python-and-mysql/">Python and MySQL</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Database connectivity using Python</h1>
<p>In this article we&#8217;ll be covering all database examples like SELECT, INSERT, UPDATE and DELETE operations using Python and MySQL database.</p>
<p><strong>First,</strong>, create database[college_db] and table[student_info] as per following image and insert few records  [here we using wamp server]  before you execute all programs in Python.</p>
<p><img decoding="async" class="alignnone wp-image-1104" src="http://www.mitindia.in/wp-content/uploads/2020/12/db-table-300x131.png" alt="" width="321" height="140" srcset="https://mitindia.in/wp-content/uploads/2020/12/db-table-300x131.png 300w, https://mitindia.in/wp-content/uploads/2020/12/db-table.png 691w" sizes="(max-width: 321px) 100vw, 321px" /></p>
<p>a) SELECT operation</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null"># pip install mysql-connector
import mysql.connector as sql

# pip install pandas
import pandas as pd

db_connection = sql.connect(host='localhost', database='college_db', user='root', password='')
db_cursor = db_connection.cursor()

db_cursor.execute('SELECT * FROM student_info')
table_rows = db_cursor.fetchall()
#without column heads
#df = pd.DataFrame(table_rows)
#print(df)
#with column heads
ch = pd.read_sql('SELECT * FROM student_info', con=db_connection)
print(ch)
</pre>
<p>Output of above code is :</p>
<p><img decoding="async" class="alignnone size-medium wp-image-1099" src="http://www.mitindia.in/wp-content/uploads/2020/12/select-300x156.png" alt="" width="300" height="156" srcset="https://mitindia.in/wp-content/uploads/2020/12/select-300x156.png 300w, https://mitindia.in/wp-content/uploads/2020/12/select.png 461w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>b) INSERT record using GUI[tkinter]</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null"># GUI - Event
from tkinter import *

#object on class Tk
window = Tk()
window.title("Welcome to GUI Python")
window.geometry('350x200')

#declaring controls
regno=Label(window,width=20, text="Reg No:", bg="yellow")
sname=Label(window, width=20,text="Name:", bg="yellow")
course=Label(window, width=20,text="Course:", bg="yellow")
ac_yr=Label(window, width=20,text="Academic Year:", bg="yellow")

txt1 = Entry(window,width=20)
txt2 = Entry(window,width=20)
txt3 = Entry(window,width=20)
txt4 = Entry(window,width=20)

#placing controls, using grid
regno.grid(column=0, row=0)
sname.grid(column=0, row=1)
course.grid(column=0, row=2)
ac_yr.grid(column=0, row=3)

txt1.grid(column=1, row=0)
txt2.grid(column=1, row=1)
txt3.grid(column=1, row=2)
txt4.grid(column=1, row=3)

#function to establish db connection and db operations
def clicked():
    import mysql.connector as sql
    import pandas as pd
    db_connection = sql.connect(host='localhost', database='college_db', user='root', password='')
    db_cursor = db_connection.cursor()
    t1=txt1.get()
    t2=txt2.get()
    t3=txt3.get()
    t4=txt4.get()
    
    db_cursor.execute("INSERT INTO student_info(regno,sname, course, aca_yr) VALUES(%s, %s, %s ,%s)", [str(t1),str(t2),str(t3),str(t4)])
    db_connection.commit()
    res="Record added successfully!"
    lb=Label(window, bg="cyan", text=res).grid(column=1,row=6)
      
btn = Button(window, text="Add Record",width=20,bg="blue",fg="white", command=clicked)
btn.grid(column=1, row=4)

#infinite loop to run application,
#wait for an event to occur and process event as long as win is not closed.
window.mainloop() 
</pre>
<p>Output of above code is :</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-medium wp-image-1106" src="http://www.mitindia.in/wp-content/uploads/2020/12/insert-1-300x196.png" alt="" width="300" height="196" srcset="https://mitindia.in/wp-content/uploads/2020/12/insert-1-300x196.png 300w, https://mitindia.in/wp-content/uploads/2020/12/insert-1.png 371w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>c) UPDATE record</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null"># pip install mysql-connector
import mysql.connector as sql
# pip install pandas
import pandas as pd

db_connection = sql.connect(host='localhost', database='college_db', user='root', password='')

db_cursor = db_connection.cursor()

db_cursor.execute("UPDATE student_info SET course='MCA' WHERE regno=1004")

db_connection.commit()
print('Record Updated')

ch = pd.read_sql('SELECT * FROM student_info', con=db_connection)
print(ch)
</pre>
<p>Output of above code is :</p>
<p><img decoding="async" class="alignnone size-medium wp-image-1099" src="http://www.mitindia.in/wp-content/uploads/2020/12/select-300x156.png" alt="" width="300" height="156" srcset="https://mitindia.in/wp-content/uploads/2020/12/select-300x156.png 300w, https://mitindia.in/wp-content/uploads/2020/12/select.png 461w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p>d) DELETE record</p>
<pre class="EnlighterJSRAW" data-enlighter-language="null"># pip install mysql-connector
import mysql.connector as sql
# pip install pandas
import pandas as pd
db_connection = sql.connect(host='localhost', database='college_db', user='root', password='')
db_cursor = db_connection.cursor()
db_cursor.execute("DELETE from student_info WHERE regno=110")
db_connection.commit()
print('Record Deleted')

ch = pd.read_sql('SELECT * FROM student_info', con=db_connection)
print(ch)
</pre>
<p>Output of above code is :</p>
<p><img loading="lazy" decoding="async" class="alignnone size-medium wp-image-1101" src="http://www.mitindia.in/wp-content/uploads/2020/12/delete-300x179.png" alt="" width="300" height="179" srcset="https://mitindia.in/wp-content/uploads/2020/12/delete-300x179.png 300w, https://mitindia.in/wp-content/uploads/2020/12/delete.png 453w" sizes="(max-width: 300px) 100vw, 300px" /></p>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fpython-and-mysql%2F&amp;linkname=Python%20and%20MySQL" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fpython-and-mysql%2F&amp;linkname=Python%20and%20MySQL" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fpython-and-mysql%2F&#038;title=Python%20and%20MySQL" data-a2a-url="https://mitindia.in/python-and-mysql/" data-a2a-title="Python and MySQL"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/python-and-mysql/">Python and MySQL</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
