MySQL Python Connectivity Commands
#CREATE DATABASE
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″)
mycursor=mydb.cursor()
mycursor.execute(“CREATE DATABASE SCHOOL”)
# SHOW DATABASE
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″)
mycursor=mydb.cursor()
mycursor.execute(“SHOW DATABASE”)
for x in mycursor:
print (x)
# CREATE TABLE
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“CREATE TABLE FEES (ROLLNO INTEGER(3),NAME VARCHAR(20),AMOUNT INTEGER(10));”)
# SHOW TABLES
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“SHOW TABLES”)
for x in mycursor:
print(x)
#DESCRIBE TABLE
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“DESC STUDENT”)
for x in mycursor:
print(x)
# SELECT QUERY
import mysql.connector
conn=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
c=conn.cursor()
c.execute(“select * from student”)
r=c.fetchone()
while r is not None:
print(r)
r=c.fetchone()
#WHERE CLAUSE
import mysql.connector
conn=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
if conn.is_connected==False:
print(“Error connecting to MYSQL DATABASE”)
c=conn.cursor()
c.execute(“select * from student where marks>90”)
r=c.fetchall()
count=c.rowcount
print(“total no of rows:”,count)
for row in r:
print(row)
# DYNAMIC INSERTION i.e insert rows/records through python
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
r=int(input(“enter the rollno”))
n=input(“enter name”)
m=int(input(“enter marks”))
mycursor.execute(“INSERT INTO student(rollno,name,marks) VALUES({},'{}’,{})”.format(r,n,m))
mydb.commit()
print(mycursor.rowcount,”RECORD INSERTED”)
# UPDATE COMMAND
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“UPDATE STUDENT SET MARKS=100 WHERE MARKS=40”)
mydb.commit()
print(mycursor.rowcount,”RECORD UPDATED”)
# DELETE COMMAND
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“DELETE FROM STUDENT WHERE MARKS<50”)
mydb.commit()
print(mycursor.rowcount,”RECORD DELETED”)
# DROP COMMAND
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“DROP TABLE STUDENT”)
# ALTER COMMAND
import mysql.connector
mydb=mysql.connector.connect(host=”localhost”,user=”root”,passwd=”12345″,database=”student”)
mycursor=mydb.cursor()
mycursor.execute(“ALTER TABLE STUDENT ADD GRADE CHAR(3)”)
Become our partner and turn clicks into cash—join the affiliate program today! https://shorturl.fm/fflOQ
Unlock exclusive rewards with every referral—enroll now! https://shorturl.fm/9GEOf
Apply now and receive dedicated support for affiliates! https://shorturl.fm/32Abq
Boost your earnings effortlessly—become our affiliate! https://shorturl.fm/23Whg
Drive sales and watch your affiliate earnings soar! https://shorturl.fm/SfvBl
Turn your network into income—apply to our affiliate program! https://shorturl.fm/QDnl5
Share our products, reap the rewards—apply to our affiliate program! https://shorturl.fm/Fgy1A
https://shorturl.fm/FP0ZK
https://shorturl.fm/5SeNL
https://shorturl.fm/RsYSC
https://shorturl.fm/DZode
https://shorturl.fm/Yejd3
https://shorturl.fm/aiezY
https://shorturl.fm/Hjld8
https://shorturl.fm/n8p3U
https://shorturl.fm/Wh7uy
https://shorturl.fm/jhILm
https://shorturl.fm/ah5jA
https://shorturl.fm/GISR8
I discovered your weblog web site on google and test just a few of your early posts. Proceed to maintain up the very good operate. I simply extra up your RSS feed to my MSN News Reader. In search of ahead to reading extra from you afterward!…
Thanks for ones marvelous posting! I really enjoyed reading it, you may be a great author.I will ensure that I bookmark your blog and will come back later in life. I want to encourage yourself to continue your great writing, have a nice morning!
Dead pent articles, Really enjoyed reading through.
Hi my friend! I want to say that this article is awesome, nice written and include almost all important infos. I would like to see more posts like this.
**mind vault**
mind vault is a premium cognitive support formula created for adults 45+. It’s thoughtfully designed to help maintain clear thinking
**glpro**
glpro is a natural dietary supplement designed to promote balanced blood sugar levels and curb sugar cravings.
**vittaburn**
vittaburn is a liquid dietary supplement formulated to support healthy weight reduction by increasing metabolic rate, reducing hunger, and promoting fat loss.
**prodentim**
prodentim an advanced probiotic formulation designed to support exceptional oral hygiene while fortifying teeth and gums.
**glucore**
glucore is a nutritional supplement that is given to patients daily to assist in maintaining healthy blood sugar and metabolic rates.
**synaptigen**
synaptigen is a next-generation brain support supplement that blends natural nootropics, adaptogens
**wildgut**
wildgutis a precision-crafted nutritional blend designed to nurture your dog’s digestive tract.
**breathe**
breathe is a plant-powered tincture crafted to promote lung performance and enhance your breathing quality.
**pinealxt**
pinealxt is a revolutionary supplement that promotes proper pineal gland function and energy levels to support healthy body function.
**energeia**
energeia is the first and only recipe that targets the root cause of stubborn belly fat and Deadly visceral fat.