MySQL history 파일 설정 및 비활성화 방법은 무엇인가요?
요약 정리
- MySQL에 입력된 쿼리는 기본적으로
.mysql_history파일에 저장됩니다. - 기본 경로는 사용자의 홈 디렉토리입니다.
MYSQL_HISTFILE환경변수를 설정하면 저장 경로를 변경할 수 있습니다.- 기록을 남기지 않으려면
/dev/null로 설정하거나 심볼릭 링크를 설정하면 됩니다.
1. MySQL history 확인 방법
.mysql_history파일에서 MySQL에서 입력한 명령어 이력을 확인할 수 있습니다.- 홈 디렉토리 내에 위치하며, 일반 사용자라면
/home/계정/.mysql_history에서 확인할 수 있습니다.
[root@localhost ~]# cat /root/.mysql_history
select�40*�40from�40processlist;
select�40*�40from�40CHARACTER_SETS;
select�40version();
show status;
show status like %version%;
status like '%version%';
show status like '%version%';
show variables like '%log%';
show variables like '%history%';
show variables;
use mysql
select * from db;
use mysql;
select * from user;
desc db;
desc user;
2. MySQL history 파일 변경 방법
- MySQL history 파일명을 변경하려면
MYSQL_HISTFILE환경변수에 원하는 경로를 설정하면 됩니다. /etc/profile이나~/.bash_profile에 아래와 같이 추가 후 적용합니다.
[root@localhost ~]# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
export MYSQL_HISTFILE=/home/mysql/data/mysql.history
적용 명령:
[root@localhost ~]# source /root/.bash_profile
변경된 history 파일로 확인:
[root@localhost ~]# cat /home/mysql/data/mysql.history
_HiStOrY_V2_
use�40mysql;
help�40hist
help�40history
use mysql
show tables;
use mysql;
select * from db;
use mysql
help use;
help insert;
[root@localhost ~]#