์ƒˆ์†Œ์‹

๐Ÿ ํŒŒ์ด์ฌ (Python)

ํŒŒ์ด์ฌ (python) Sqlite ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค Dump ๋ฐฑ์—…, ๋คํ”„

  • -

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋ฐฑ์—…ํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ, ๋งŒ์•ฝ ์œ„ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์€ ๋‚ด์šฉ์˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๊ฐ€ ์žˆ๋‹ค๋ฉด, ์ด ๋‚ด์šฉ์„ ๋˜‘๊ฐ™์ด ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๋คํ”„ํŒŒ์ผ์„ ์ƒ์„ฑํ•œ๋‹ค.

import sqlite3

conn = sqlite3.connect('db1.sqlite')
c = conn.cursor

conn.execute("SELECT * FROM users ")


with conn:
    with open('..db1_dump.sql','w') as f :
        for line in conn.iterdump():
            f.write('%s\n' %line)
    

 

db1_dump.sql ์ด๋ผ๋Š” ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค. 

 

BEGIN TRANSACTION;
CREATE TABLE users(id INTEGER PRIMARY KEY, username TEXT, email TEXT, phone TEXT, regist_date TEXT);
INSERT INTO "users" VALUES(2,'park','Park@naver,com','010-2224-2412','2020-02-23 16:55:17.658330');
INSERT INTO "users" VALUES(5,'Kim','kim@naver.com','010-2512-1212','2020-02-23 16:51:28.214145');
INSERT INTO "users" VALUES(13,'Lee','Lee@naver.com','010-2222-2222','2020-02-23 17:02:10.602053');
INSERT INTO "users" VALUES(23,'Lee','Lee@naver.com','010-2222-2222','2020-02-23 17:02:10.602053');
INSERT INTO "users" VALUES(33,'Lee','Lee@naver.com','010-2222-2222','2020-02-23 17:02:10.602053');
COMMIT;

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.