mysql 레코드 data 치환
MDL정보를 확인 중 제공된 데이터에서 아래와 같이 문제가 있는 domain 정보가 있는 것이 확인됨
| 766440.comhttps: |
| aa-concrete.comhttps: |
| akucintapasuruan.idhttps: |
| alpha-lam.co.ukhttps: |
도메인 끝 부분에 "https:" 가 붙어 있는 불량 데이터임
* mysql database 에서 이와 같은 데이터를 모두 변경하는 방법
- 데이터 확인 (변경 시 문제가 없는지)
mysql> select replace(domain, 'https:', '') from <TableName> where domain like '%https:';
| 766440.com |
| aa-concrete.com |
| akucintapasuruan.id |
| alpha-lam.co.uk
- 정상으로 확인되면 변경 작업
mysql> update <TableName> set domain = replace(domain, 'https:', '') where domain like '%https:';
- "https:" 가 제거되어 저장되는 데이터 중 기존의 데이터와 중복되어 duplicate entry 에러가 발생하는 경우가 있음
아래와 같이 실행하면 중복되는 부분은 무시하고 업데이트됨
mysql> update ignore <TableName> set domain = replace(domain, 'https:', '') where domain like '%https:';
- 중복되어 변경되지 않은 데이터는 아래와 같이 제거
mysql> delete from mdl_2017 where domain like '%https:';