打造Linux下超级安全的LAMP服务器(中)
接着我们修改mysql数据库里的东西,不过不管怎么样,我们首先得给mysql设置一个密码并修改管理员用户名(默认是root),但一定得记得,无论怎么样修改密码,都会有记录的,如果通过mysqladmin修改,shell的历史记录会有的,如果登陆了mysql之后再修改,在~/.mysql_history会记录的,所以我们一定得处理这两个历史记录文件,我们把他们删了,再从/dev/null做个软连接过来就可以解决问题了
[root@debian /]cd ~
[root@debian ~]ll
total 13K
-rw------- 1 root root 1.8K Sep 28 21:05 .bash_history
-rw------- 1 root root 14 Sep 29 09:29 .mysql_history
我们可以看到这两个文件里面都记录了东西的,下面我们处理他们
[root@debian ~]rm .bash_history
[root@debian ~]rm .mysql_history
[root@debian ~]ln -s /dev/null .bash_history
[root@debian ~]ln -s /dev/null .mysql_history
我们再看看
[root@debian ~][root@debian ~]ll
total 10K
lrwxrwxrwx 1 root root 9 Sep 29 09:29 .bash_history -> /dev/null
lrwxrwxrwx 1 root root 9 Sep 29 09:29 .mysql_history -> /dev/null
现在可以放心的设置密码了
[root@debian ~]mysqladmin -u root password mypasswd
这样我们以后root就得通过"mypasswd"这个密码来访问mysql数据库了
然后我们删除多余的数据库并去掉匿名帐号
[root@debian ~]mysql -u root -p
Enter password:XXXXXX
mysql> drop database test;
mysql> use mysql;
mysql> delete from db;
mysql> delete from user where not (host="localhost" and user="root");
mysql> flush privileges;
然后修改默认的管理员帐号root为你喜欢的,我这里改成fatb
mysql> update user set user="fatb" where user="root";
mysql> flush privileges;
以后我们就得通过fatb帐号访问mysql数据库了
[root@debian ~]mysql -u root -p
Enter password:
ERROR 1045: Access denied for user: ''root@localhost'' (Using password: YES)
[root@debian ~]mysql -u fatb -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 14 to server version: 4.0.13-log
到这里,mysql的安全设置基本上完毕了