Connectivity Commands
Connectivity Commands
Connectivity Commands
2. Open database
Mysql>use covid;
3. To create table by using field names
Mysql> create table patient (pno int, name
varchar(15), age int, address varchar(15),
contactno int);
4. Insert four records in the patient table
Mysql>insert into patient values(1,’akash’,
…………);
5. Open a new file in python
USING SELECT COMMAND IN PYTHON-MYSQL CONNECTIVITY
>>>
== RESTART: C:\Users\gateway\AppData\Local\Programs\Python\Python38\sqltor.py ==
mydb=sqltor.connect(host="localhost",user="root",password="arshad123",database="arshad")
mycursor=mydb.cursor()
mycursor.execute("show tables")
for i in mycursor:
print(i)
output:
== RESTART: C:\Users\gateway\AppData\Local\Programs\Python\Python38\sqltor.py ==
('ali',)
insert command
+------+--------+------------------+
| No | Name | qualities |
+------+--------+------------------+
| 1 | arshad | singer_cricketer |
| 2 | irshad | singer_cricketer |
| 1 | Rahul | artist |
+------+--------+------------------+
mydb=sqltor.connect(host="localhost",user="root",password="arshad123",database="arshad")
mycursor=mydb.cursor()
mydb.commit()
output:
+------------+-------------+------+-----+---------+-------+
+------------+-------------+------+-----+---------+-------+
+------------+-------------+------+-----+---------+-------+
mydb=sqltor.connect(host="localhost",user="root",password="arshad123",database="arshad")
mycursor=mydb.cursor()
for i in mycursor:
print(i)
output:
== RESTART: C:\Users\gateway\AppData\Local\Programs\Python\Python38\sqltor.py ==
('arshad',)
('Rahul',)
update command
import mysql.connector as sqltor
mydb=sqltor.connect(host="localhost",user="root",password="arshad123",database="arshad")
mycursor=mydb.cursor()
mydb.commit()
output:
+------+--------+------------------+
| No | Name | qualities |
+------+--------+------------------+
| 1 | steve | singer_cricketer |
| 2 | irshad | singer_cricketer |
| 1 | steve | artist |
+------+--------+------------------+
show databases
import mysql.connector as sqltor
mydb=sqltor.connect(host="localhost",user="root",password="arshad123",database="arshad")
mycursor=mydb.cursor()
mycursor.execute("show databases")
for i in mycursor:
print(i)
output:
== RESTART: C:\Users\gateway\AppData\Local\Programs\Python\Python38\sqltor.py ==
('information_schema',)
('apollo',)
('arshad',)
('biology',)
('candidate',)
('class',)
('cricket',)
('employee',)
('factory',)
('hospital',)
('lib',)
('mysql',)
('performance_schema',)
('student',)
('test',)
delete
command
import mysql.connector as sqltor
mydb=sqltor.connect(host="localhost",user="root",password="arshad123",database="arshad")
mycursor=mydb.cursor()
mydb.commit()
output:
+------+--------+------------------+
| No | Name | qualities |
+------+--------+------------------+
| 2 | irshad | singer_cricketer |
+------+--------+------------------+
* -------------------------------------------------------*