-
Notifications
You must be signed in to change notification settings - Fork 6
database (mysql workbench, pymysql, aws)
egoing edited this page Oct 6, 2021
·
6 revisions
CREATE DATABASE `topics`;
CREATE TABLE `author` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`profile` varchar(145) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
CREATE TABLE `topic` (
`id` int NOT NULL AUTO_INCREMENT,
`title` varchar(45) NOT NULL,
`body` text,
`author_id` int DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
import pymysql.cursors
connection = pymysql.connect(host='database-1.cdbrt00yi2pz.ap-northeast-2.rds.amazonaws.com',
user='admin',
password='11111111',
database='topics',
cursorclass=pymysql.cursors.DictCursor)
cursor = connection.cursor()
sql = "SELECT * FROM topics"
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
print(str(row['id'])+', '+row['title']+', '+row['body'])import pymysql.cursors
connection = pymysql.connect(host='database-1.cdbrt00yi2pz.ap-northeast-2.rds.amazonaws.com',
user='admin',
password='11111111',
database='topics',
cursorclass=pymysql.cursors.DictCursor)
title = input('title : ')
body = input('body : ')
cursor = connection.cursor()
sql = "INSERT INTO topics (title, body) VALUES(%s, %s)"
cursor.execute(sql, (title, body))
connection.commit()