-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmysql_join.py
More file actions
55 lines (42 loc) · 1.08 KB
/
Copy pathmysql_join.py
File metadata and controls
55 lines (42 loc) · 1.08 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
"""
@Author: Aseem Jain
@Linkedin: https://www.linkedin.com/in/premaseem/
@Github: https://github.com/premaseem/pythonLab/tree/master/challenge
"""
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="premdatabase"
)
print(mydb)
mycursor = mydb.cursor()
# mycursor.execute("CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), fav INT)")
#
# # INSERT MANY
# sql = "INSERT INTO users (name, fav) VALUES (%s, %s)"
# val = [
# ('Peter', 154),
# ('Amy', 155),
# ('Hannah', 153),
# ('Michael', 156),
# ('Sandy', 154),
# ('Betty', 154),
# ]
#
# mycursor.executemany(sql, val)
# mydb.commit()
#
# print(mycursor.rowcount, "was inserted.")
sql = "CREATE TABLE products (id INT, name varchar(50))"
# mycursor.execute(sql)
sql = "INSERT INTO products VALUES (%s, %s)"
val = [
( 154, 'Chocolate Heaven' ),
( 155, 'Tasty Lemons' ),
( 156, 'Vanilla Dreams' )
]
# mycursor.executemany(sql,val)
mycursor.execute("INSERT INTO products VALUES (157,'condom')")
mydb.commit()