防止MySQL密码泄露(MySQL安全)

1、可以通过环境变量来强制LINUX不记录敏感历史命令

在命令行执行“HISTCONTROL=ignorespace”后,再在输入带密码的命令前面加一个空格登录,登录命令不会被记录到历史记录里。

# HISTCONTROL=ignorespace
#  mysql -uroot -p'passwd'

2、操作完敏感的命令后及时删除命令行记录

可执行“history -d 历史命令序号”清除指定历史记录命令。

# history|tail -4      查看历史命令最后4条命令记录
 1007  cat /etc/passwd
 1008  history
 1009  history
 1010  history|tail -4

# history -d 1010     删除历史命令编号1010的历史记录

# history | tail -6     查看历史命令最后6条记录,发现原来编号1010的记录已经被删除
 1006  history
 1007  cat /etc/passwd
 1008  history
 1009  history
 1010  history -d 1010
 1011  history | tail -6

 

可执行 “history -c” 清除所有记录
#history -c

也可以执行 “>~/.bash_history”清除历史记录文件

3、为带密码的启动脚本以及备份脚本等加700权限,用户和组改为root

chmod 700 /data/3306/mysql
chmod 700 /server/scripts/bak.sh

4、把密码写入my.cnf配置文件并加600权限,用户和组改为mysql

# grep -A 2 client /etc/my.cnf
[client]
user = root
password = 123456

# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.5.61-log Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

 

posted @ 2019-03-24 09:58  miclesvic  阅读(510)  评论(0)    收藏  举报