mysql的历史命令记录,~/.mysql_history,指定该文件路径
2016-01-09 11:22
731 查看
~/.mysql_history文件中记录每个用户使用数据库的操作命令
root用户的mysql操作,~/.mysql_history
transfor用户的mysql操作,/home/transfor/.mysql_history
[root@cp-mysql01-new ~]# tail -20 /root/.mysql_history
show variables like '%resolve%';
show variables like '%connection%';
show global status like ‘Max_used_connections;
show global status like ‘Max_used_connections';
show global status like 'max_user_connections';
show global status like 'max_used_connections';
show global variables like 'max_user_connections';
show global status like '%open%table%';
show variables like 'table%cache%';
show global status like 'thread%';
show variables like 'thread_cache_size';
show global status like 'qcache%';
show variables like 'query_cache%';
select count(id) from mop_bet_order_history;
use lottery;
select count(id) from mop_bet_order_history;
不过这个文件会把所有操作记录下来,包括创建用户和修改用户的明文密码。万一被人攻击,获取该文件内容,非常危险。
这个文件是mysql编译安装时默认配置好的,不容易修改。但是最好不要保存,仅仅删除是不行的,要直接将其软连接到垃圾箱:
rm ~/.mysql_history
ln -s /dev/null ~/.mysql_history
如果确实想将一些操作记录下来,可以在/etc/my.cnf配置文件的[client]组临时添加:
[client]
tee=/tmp/mysql.history
tee命令添加完成后,无需重启mysql服务,所以仅对当前打开的客户端记录mysql操作命令
等操作使用完成后,注释
~/.mysql_history文件产生原理
因为mysql本身就是一个shell,每次mysql连接退出后,都会把此次操作信息记录到~/.mysql_history文件中
如果该文件不存在,会先创建再记录(像rm,或者刚安装的mysql)
此文件的名字和路径,是根据MYSQL_HISTFILE这个环境变量来设置的,默认是~/.mysql_history,修改文件名和路径:
vim ~/.bash_profile
export MYSQL_HISTFILE=/home/jason/.my_history
./etc/profile重新初始化后,生效
root用户的mysql操作,~/.mysql_history
transfor用户的mysql操作,/home/transfor/.mysql_history
[root@cp-mysql01-new ~]# tail -20 /root/.mysql_history
show variables like '%resolve%';
show variables like '%connection%';
show global status like ‘Max_used_connections;
show global status like ‘Max_used_connections';
show global status like 'max_user_connections';
show global status like 'max_used_connections';
show global variables like 'max_user_connections';
show global status like '%open%table%';
show variables like 'table%cache%';
show global status like 'thread%';
show variables like 'thread_cache_size';
show global status like 'qcache%';
show variables like 'query_cache%';
select count(id) from mop_bet_order_history;
use lottery;
select count(id) from mop_bet_order_history;
不过这个文件会把所有操作记录下来,包括创建用户和修改用户的明文密码。万一被人攻击,获取该文件内容,非常危险。
这个文件是mysql编译安装时默认配置好的,不容易修改。但是最好不要保存,仅仅删除是不行的,要直接将其软连接到垃圾箱:
rm ~/.mysql_history
ln -s /dev/null ~/.mysql_history
如果确实想将一些操作记录下来,可以在/etc/my.cnf配置文件的[client]组临时添加:
[client]
tee=/tmp/mysql.history
tee命令添加完成后,无需重启mysql服务,所以仅对当前打开的客户端记录mysql操作命令
等操作使用完成后,注释
~/.mysql_history文件产生原理
因为mysql本身就是一个shell,每次mysql连接退出后,都会把此次操作信息记录到~/.mysql_history文件中
如果该文件不存在,会先创建再记录(像rm,或者刚安装的mysql)
此文件的名字和路径,是根据MYSQL_HISTFILE这个环境变量来设置的,默认是~/.mysql_history,修改文件名和路径:
vim ~/.bash_profile
export MYSQL_HISTFILE=/home/jason/.my_history
./etc/profile重新初始化后,生效
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复