본문 바로가기

Development/Servers

MySQL 문자열 치환, 데이터 덤프 및 복원, 문자열 나누기

서비스하는 사이트의 파일 경로가 변경되는 문제가 있어서 초기 데이터에 삽입된 파일 경로 관련 문자열을 변경해야할 필요가 생겼다. 보통 cheat sheet 한장만 보고 코딩하고 있었는데 실제 서비스 중인 곳이라 함부로 변경하긴 자신이 없었다.

구글님 도와줘요.


(두둥)


이하 스크랩 - (출처)

필드데이타를 변경해주는 방법입니다.
REPLACE(필드명, 수정전 문자열, 수정후 문자열)
 
나같은 경우는 데이타에 저장된 아이피를 네트워크 대역을 변경하기 위해 사용했다.
mysql>  update 130_policy set server_ip=replace(server_ip,'xxx.xxx.121','xxx.xxx.252');
Query OK, 18 rows affected (0.04 sec)
Rows matched: 18  Changed: 18  Warnings: 0
 
mysql>  update 130_policy set destination_ip=replace(destination_ip,'xxx.xxx.121','xxx.xxx.252');
Query OK, 17 rows affected (0.00 sec)
Rows matched: 18  Changed: 17  Warnings: 0




에고고 기억력 때문에 블로깅을 하는 것 같음 ㅡㅜ;

원격 MySQL 데이터베이스 접속

mysql -h db.domain.co.kr -u username -p password


데이터 덤프 및 복원 스크립트 (CCCV용)

mysqldump -p onweekend > onweekend.sql
mysql -uroot -p --default-character-set=euckr onweekend < onweekend.sql



-

문자열 나누기용

SUBSTRING_INDEX(adddata,'|',1) as address,
SUBSTRING_INDEX(SUBSTRING_INDEX(adddata,'|',2),'|',-1) as tel,
SUBSTRING_INDEX(SUBSTRING_INDEX(adddata,'|',6),'|',-1) as category