-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_db.py
More file actions
51 lines (40 loc) · 1.06 KB
/
build_db.py
File metadata and controls
51 lines (40 loc) · 1.06 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
import pandas as pd
import mysql.connector
from mysql.connector import Error
def connect(db):
try:
conn=mysql.connector.connect(host='YOUR HOST',
database=YOUR DATABASE,
user='root',
password='YOUR PASSWORD')
if conn.is_connected():
print('connected to the database!')
except Error as e:
print(e)
finally:
conn.close()
def create_database(cursor):
try:
cursor.execute(
"CREATE DATABASE{} ".format(wechat))
except Error as e:
print e
def create_tables():
try:
order1 = 'CREATE TABLE IF NOT EXISTS house_info(
house_id INT(5) NOT NULL AUTO_INCREMENT
house_owner VARCHAR(10) NOT NULL
house_di
)
'
order2 = 'CREATE TABLE IF NOT EXISTS house_feature'
order3 = 'location
TABLES = {}
TABLES['message'] = (
"CREATE TABLE message("
"contact_id INT(3) NOT NULL"
"message_id INT(6) NOT NULL AUTO_INCREMENT,"
"sent_date DATE NOT NULL"
"time "
"PRIMARY KEY(contact_id)"
)