티스토리 뷰

최근에 웹 서버를 구현하고 있는데 종종 DB Schema도 바뀌고 우분투를 다루는데도 익숙치 않아서 자주 서버를 갈아 엎어서 기껏 만들어놓았던 더미 데이터들이 날라가서 너무 마음이 아파서 어떻게 할까 고민하다가

 

한 번 집어넣은 데이터를 엑셀 파일로 뽑아냈다가 이후에 DB Schema를 갈아 엎을 때 마다 엑셀 파일을 활용해서 넣어주면 좋겠다 싶었습니다.

 

그래서 찾아 본 결과

1. MySql Table에서 csv 파일로 Export 

SELECT *
FROM Tablename
INTO OUTFILE '[저장경로]/result.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

 

그러나 뜻하지 않은 에러에 직면했으니..

 

The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

 

아래 블로그 글을 참고해서 해결하였다.

sssunho.tistory.com/56

 

[MySQL] Load Data 시도 중 secure_file_priv 문제 직면

Load Data를 시도하던 중, The MySQL server is running with the --secure-file-priv option so it cannot execute this statement 문제에 직면하였다. 1. MySQL에 접속하여 변수 상태를 확인한다 mysql> SELECT..

sssunho.tistory.com

그리고 또 진행했는데 또 에러가 뜸

 

Can't create/write to file (OS errno 13 - Permission denied)

 

다시 아래 사이트 내용으로 해결하고

programmersought.com/article/78195338555/

 

ubuntu mysql executes INTO OUTFILE error: Can't create/write to file'/tmp/' (Errcode: 13-Permission denied) - Programmer Sought

Environment: ubuntu, mysql5.7 Error: (HY000): Can’t create/write to file ‘/tmp/test.txt’ (Errcode: 13-Permission denied) First the path matchessecure_file_privSet up Reason 1: (Insufficient permissions of the directory) ls -l chmod Permission number

programmersought.com

 

2. csv 파일을 MySql Table로 Import

LOAD DATA INFILE '[저장경로]/result.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '/n'

 

 

참고

stackoverflow.com/questions/19586057/how-to-i-export-mysql-data-to-excel

 

How to i export Mysql Data to excel?

How do i export mysql table data to microsoft excel? is there a way to write a query to output this data? i am assuming the query should take the form SELECT * FROM Tablename OUTPUT INTO SOMEF...

stackoverflow.com

phoenixnap.com/kb/import-csv-file-into-mysql

 

How to Import a CSV File in MySQL? {Command Line or phpMyAdmin}

Learn how to import a CSV file into MySQL within minutes. The guide covers 2 different methods. Import a CSV from the command line or by using phpMyAdmin.

phoenixnap.com

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함