-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyMysql.py
More file actions
66 lines (55 loc) · 1.76 KB
/
PyMysql.py
File metadata and controls
66 lines (55 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
import pymysql
def sel():
# sel
my_conn= pymysql.connect(host="192.168.92.128",
user='sa',
passwd='zhouyf',
db='cbs')
my_cur=my_conn.cursor()
my_cur.execute("select * from products")
print()
for row in my_cur:
print(row)
my_cur.close()
my_conn.close()
def del(): #demo
my_conn= pymysql.connect(host="192.168.92.128",
user='sa',
passwd='zhouyf',
db='cbs')
my_cur=my_conn.cursor()
sql = "delete from products where name = '%s' limit %d"
datas = ('Sara', 2)
my_cur.execute(sql % datas)
my_conn.commit()
print('成功删除姓名为', datas[0], '的', my_cur.rowcount, '条数据')
my_cur.close()
my_conn.close()
def ins(): #demo
my_conn = pymysql.connect(host="192.168.92.128",
user='sa',
passwd='zhouyf',
db='cbs')
my_cur = my_conn.cursor()
sql = "insert into py_tab(name) values ('%s')"
names = input("请输入要插入的人名:")
my_cur.execute(sql % names)
my_conn.commit()
print(names, '已成功插入')
my_cur.close()
my_conn.close()
def upd():
my_conn = pymysql.connect(host="192.168.92.128",
user='sa',
passwd='zhouyf',
db='cbs')
my_cur = my_conn.cursor()
sql = "update python.py_tab set name = '%s' where name = '%s'"
datas = ('Lily', 'Chuck')
my_cur.execute(sql % datas)
my_conn.commit()
print('成功匹配并修改了', my_cur.rowcount, '条数据')
my_cur.close()
my_conn.close()
sel()