-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate_DataBase.py
More file actions
28 lines (27 loc) · 2.91 KB
/
Create_DataBase.py
File metadata and controls
28 lines (27 loc) · 2.91 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
import pymysql
class CreateDatabase:
def create(self):
#change this config to yourself's
connection = pymysql.connect(host='localhost', port=3306, user='root', password='XXXXXX', db='music',
charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
with connection.cursor() as cursor:
new_music_sql = '''create table `new_music`(`id` int(11) NOT NULL ,`name` VARCHAR(256) COLLATE utf8_bin NOT NULL ,`album` VARCHAR(256) COLLATE utf8_bin NOT NULL ,
`album_id` int(11) COLLATE utf8_bin NOT NULL,`url` VARCHAR(256) COLLATE utf8_bin NOT NULL,`artist` VARCHAR(256) COLLATE utf8_bin NOT NULL,
`duration` int(11) COLLATE utf8_bin NOT NULL , `pic` VARCHAR(256) COLLATE utf8_bin NOT NULL , PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin AUTO_INCREMENT=1'''
hot_music_sql = '''create table `hot_music`(`id` int(11) NOT NULL ,`name` VARCHAR(256) COLLATE utf8_bin NOT NULL ,`album` VARCHAR(256) COLLATE utf8_bin NOT NULL ,
`album_id` int(11) COLLATE utf8_bin NOT NULL,`url` VARCHAR(256) COLLATE utf8_bin NOT NULL,`artist` VARCHAR(256) COLLATE utf8_bin NOT NULL,
`duration` int(11) COLLATE utf8_bin NOT NULL , `pic` VARCHAR(256) COLLATE utf8_bin NOT NULL , PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin AUTO_INCREMENT=1'''
billboard_music_sql = '''create table `billboard_music`(`id` int(11) NOT NULL ,`name` VARCHAR(256) COLLATE utf8_bin NOT NULL ,`album` VARCHAR(256) COLLATE utf8_bin NOT NULL ,
`album_id` int(11) COLLATE utf8_bin NOT NULL,`url` VARCHAR(256) COLLATE utf8_bin NOT NULL,`artist` VARCHAR(256) COLLATE utf8_bin NOT NULL,
`duration` int(11) COLLATE utf8_bin NOT NULL , `pic` VARCHAR(256) COLLATE utf8_bin NOT NULL , PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin AUTO_INCREMENT=1'''
pop_music_sql = '''create table `pop_music`(`id` int(11) NOT NULL ,`name` VARCHAR(256) COLLATE utf8_bin NOT NULL ,`album` VARCHAR(256) COLLATE utf8_bin NOT NULL ,
`album_id` int(11) COLLATE utf8_bin NOT NULL,`url` VARCHAR(256) COLLATE utf8_bin NOT NULL,`artist` VARCHAR(256) COLLATE utf8_bin NOT NULL,
`duration` int(11) COLLATE utf8_bin NOT NULL , `pic` VARCHAR(256) COLLATE utf8_bin NOT NULL , PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin AUTO_INCREMENT=1'''
cursor.execute("drop table if exists new_music")
cursor.execute("drop table if exists hot_music")
cursor.execute("drop table if exists billboard_music")
cursor.execute("drop table if exists pop_music")
cursor.execute(new_music_sql)
cursor.execute(hot_music_sql)
cursor.execute(billboard_music_sql)
cursor.execute(pop_music_sql)