IT/Database
[MariaDB] 쿼리 모음
yeTi
2016. 10. 24. 12:16
안녕하세요. yeTi입니다.
오늘은 MariaDB에서 사용할 수 있는 쿼리를 모아보겠습니다.
1. 데이터베이스 내보내기
mysqldump -u[계정] -p[비밀번호] [데이터베이스명] > [저장할 파일명]
2. 데이터 베이스 가져오기
mysql -u[계정] -p < [임포트할 파일명]
3. 로그인하기
mysql -u[계정] -p -h[호스트]
4. 데이터베이스 생성하기
CREATE DATABASE [DB명];
5. 문자열 나누기
- SUBSTRING(str,pos),
- SUBSTRING(str FROM pos),
- SUBSTRING(str,pos,len),
- SUBSTRING(str FROM pos FOR len)
- SUBSTR(str,pos),
- SUBSTR(str FROM pos),
- SUBSTR(str,pos,len),
- SUBSTR(str FROM pos FOR len)
6. 문자열 위치 가져오기
- LOCATE(substr,str)
- LOCATE(substr,str,pos)
7. XML 파싱하기
- ExtractValue([컬럼 명], 'depth1 element name/depth2 element name')
- ExtractValue([컬럼 명], 'depth1 element name/@attribute name')
8. 데이터베이스별 크기 조회
- SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
9. 테이블별 크기 조회
- SELECT
table_name,
table_rows,
round(data_length/(1024*1024),2) as 'DATA_SIZE(MB)',
round(index_length/(1024*1024),2) as 'INDEX_SIZE(MB)'
FROM information_schema.TABLES
where table_schema = '[데이터베이스 명]'
GROUP BY table_name
ORDER BY data_length DESC
LIMIT 10;
관련 글
참고 문헌
- MariaDB 홈페이지 : https://mariadb.com/kb/ko/basic-sql-statements/