-->shell>ls -l /usr/local/mysql
total 40
drwxrwxr-x 2 root root 4096 Feb 27 20:07 bin
drwxrwxr-x 3 root root 4096 Feb 27 20:07 include
drwxrwxr-x 2 root root 4096 Feb 27 20:07 info
drwxrwxr-x 3 root root 4096 Feb 27 20:07 lib
drwxrwxr-x 2 root root 4096 Feb 27 20:07 libexec
drwxrwxr-x 3 root root 4096 Feb 27 20:07 man
drwxrwxr-x 6 root root 4096 Feb 27 20:07 mysql-test
drwxrwxr-x 3 root root 4096 Feb 27 20:07 share
drwxrwxr-x 7 root root 4096 Feb 27 20:07 sql-bench
drwx------ 4 mysql mysql 4096 Feb 27 20:07 var
shell>ls -l /usr/local/mysql/var
total 8
drwx------ 2 mysql mysql 4096 Feb 27 20:08 mysql
drwx------ 2 mysql mysql 4096 Feb 27 20:08 test
shell>ls -l /usr/local/mysql/var/mysql
total 104
-rw------- 1 mysql mysql 0 Feb 27 20:08 columns_priv.MYD
-rw------- 1 mysql mysql 1024 Feb 27 20:08 columns_priv.MYI
-rw------- 1 mysql mysql 8778 Feb 27 20:08 columns_priv.frm
-rw------- 1 mysql mysql 302 Feb 27 20:08 db.MYD
-rw------- 1 mysql mysql 3072 Feb 27 20:08 db.MYI
-rw------- 1 mysql mysql 8982 Feb 27 20:08 db.frm
-rw------- 1 mysql mysql 0 Feb 27 20:08 func.MYD
-rw------- 1 mysql mysql 1024 Feb 27 20:08 func.MYI
-rw------- 1 mysql mysql 8641 Feb 27 20:08 func.frm
-rw------- 1 mysql mysql 0 Feb 27 20:08 host.MYD
-rw------- 1 mysql mysql 1024 Feb 27 20:08 host.MYI
-rw------- 1 mysql mysql 8958 Feb 27 20:08 host.frm
-rw------- 1 mysql mysql 0 Feb 27 20:08 tables_priv.MYD
-rw------- 1 mysql mysql 1024 Feb 27 20:08 tables_priv.MYI
-rw------- 1 mysql mysql 8877 Feb 27 20:08 tables_priv.frm
-rw------- 1 mysql mysql 428 Feb 27 20:08 user.MYD
-rw------- 1 mysql mysql 2048 Feb 27 20:08 user.MYI
-rw------- 1 mysql mysql 9148 Feb 27 20:08 user.frm
如果这些文件的属主及属性不是这样,请用以下两个命令修正之:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
<--page1--> 2、外部网络安全
MySQL数据库安装好以后,Unix平台的user表是这样的:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->mysql> use mysql;
Database changed
mysql> select Host,User,Password,Select_priv,Grant_priv from user;
图1
3、 rows in set (0.00 sec)
Windows平台的user表是这样的:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->mysql> use mysql;
Database changed
mysql> select Host,User,Password,Select_priv,Grant_priv from user;
图2
我们先来看Unix平台的user表。其中redhat只是我试验机的机器名,所以实际上Unix平台的MySQL默认只允许本机才能连接数据库。但是缺省root用户口令是空,所以当务之急是给root用户加上口令。给数据库用户加口令有三种方法:
1)在shell提示符下用mysqladmin命令来改root用户口令:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->shell>mysqladmin -uroot password test
这样,MySQL数据库root用户的口令就被改成test了。(test只是举例,我们实际使用的口令一定不能使用这种易猜的弱口令)
2)用set password修改口令:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->mysql> set password for root@localhost=password('test');
这时root用户的口令就被改成test了。
3)直接修改user表的root用户口令:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->mysql> use mysql;
mysql> update user set password=password('test') where user='root';
mysql> flush privileges;
这样,MySQL数据库root用户的口令也被改成test了。其中最后一句命令flush privileges的意思是强制刷新内存授权表,否则用的还是缓冲中的口令,这时非法用户还可以用root用户及空口令登陆,直到重启MySQL服务器。
我们还看到user为空的匿名用户,虽然它在Unix平台下没什么权限,但为了安全起见我们应该删除它:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->mysql> delete from user where user='';
Windows版本MySQL的user表有很大不同,我们看到Host字段除了localhost还有是%。这里%的意思是允许任意的主机连接MySQL服务器,这是非常不安全的,给攻击者造成可乘之机,我们必须删除Host字段为%的记录:<--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->mysql>de
<---content end---> 作者: 零度赤道 时间: 2011-3-2 20:19
very good!