Category: MySQL

0

MySQL - Top N 쿼리 확인 방법

MySQL에서 가장 많이 실행되거나 느린 쿼리를 확인하는 방법을 정리합니다. Log 파일 기반 Top N 쿼리 확인5. Slow Query Log 설정-- Slow Query Log 활성화SET GLOBAL slow_query_log = 'ON';-- Slow Query 기준 시간 설정 (초 단위)SET GLOBAL long_query_time = 2;-- Slow Query Log 파일 위치 확인SHOW VARIABLES LIKE 'slow_query_log_file';-- 인덱스를 사용하지 않는 쿼리도 로깅SET GLOBAL log_queries_not_using_indexes = 'ON'; SHOW VARIABLES LIKE 'slow_query%';SHOW VARIABLES LIKE 'long_query_time'; SHOW VARIABLES LIKE 'slow_query_log_file'; 6. Slow Query Log 분석 (mysqldumpslow)# 가장 느린 쿼리 10개mysqldumpslow -s t -t 10 /path/to/slow-query.log# 가장 많이 실행된 쿼리 10개mysqldumpslow -s c -t 10 /path/to/slow-query.log# 평균 실행 시간이 긴 쿼리 10개mysqldumpslow -s at -t 10 /path/to/slow-query.log Performance Schema를 이용한 Top N 쿼리 확인

0

MySQL - 사용자 추가

사용자 추가create user '[userid]';-- localhost 에서만 접속할 수 있는 계정 생성create user '[userid]'@'localhost' identified by '[비밀번호]';-- 외부에서 접근 가능한 계정 생성create user '[userid]'@'%' identified by '[비밀번호]'; 권한 부여하기-- select 권한 부여grant select privileges on *.* to '[userid]'@localhost identified by '[비밀번호]';-- update 권한 부여grant update privileges on *.* to '[userid]'@localhost identified by '[비밀번호]';-- insert 권한 부여grant insert privileges on *.* to '[userid]'@localhost identified by '[비밀번호]';-- delete 권한 부여grant delete privileges on *.* to '[userid]'@localhost identified by '[비밀번호]';-- select, update, insert 권한 부여grant select, update, insert privileges on *.* to '[userid]'@localhost identified by '[비밀번호]'; 특정 데이터 베이스에 대한 접근 부여-- [Database 명] 데이터베이스에 select 권한 부여grant select privileges on [Database 명].* to '[userid]'@localhost identified by '[비밀번호]'; User 에 따른 데이터 베이스 접근 부여-- localhost User 에게 전체 권한 부여grant all privileges on *.* to '[userid]'@localhost identified by '[비밀번호]';-- 외부접근 User 에게 전체 권한 부여grant all privileges on *.* to '[userid]'@'%' identified by '[비밀번호]';

0

MySQL - 사용자 생성

MySQL - 사용자 생성show databases; use mysql; 계정 생성 쿼리-- 내부에서만 사용할 계정 생성CREATE USER '계정 아이디'@'localhost' IDENTIFIED BY '비밀번호';-- 외부에서 사용할 계정 생성CREATE USER '계정 아이디'@'%' IDENTIFIED BY '비밀번호'; 권한 부여-- GRANT ALL PRIVILEGES ON *.* TO '계정 아이디'@'%';flush privileges;quit$$ CREATE DATABASE study_db default CHARACTER SET UTF8;