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 ~]#
3. MySQL history를 남기지 않도록 설정하는 방법
① 기존 history 삭제 방법
- 아래 중 하나의 방법으로
.mysql_history내용을 삭제할 수 있습니다.
[root@localhost ~]# rm -rf .mysql_history
또는
[root@localhost ~]# cat /dev/null > .mysql_history
② MYSQL_HISTFILE을 /dev/null로 설정하기
- 이후의 기록을 저장하지 않도록 하기 위해
/dev/null로 설정합니다.
[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=/dev/null
적용 명령:
[root@localhost ~]# source /root/.bash_profile
③ .mysql_history를 /dev/null에 심볼릭 링크로 연결
- 다음 명령어로
.mysql_history파일이 생성되지 않도록 할 수 있습니다.
[root@localhost ~]# rm -rf .mysql_history
[root@localhost ~]# ln -s /dev/null .mysql_history
[root@localhost ~]# ls -l .mysql_history
lrwxrwxrwx 1 root root 9 Feb 18 11:15 .mysql_history -> /dev/null
[root@localhost ~]#