java.sql.SQLException:Can't create/write to file 'c:\windows\temp\#sql_1218_0.myd'<Errcode:17>

在我的一个jsp项目从tomcat下移植到resin后,链接数据库提取数据总会抛出以上异常,后来查资料,得知:

一、

在对mysql进行的每次操作,mysql本身都要去访问临时文件夹。如果该文件夹不存在就会报错,而且如果该临时文件夹中生成了类似#sql*******.MYD的文件,mysql也会报错。

目前的解决方案是不采用默认的临时文件夹,自己重新建一个临时文件夹。 更改mysql的临时文件夹的方法如下:

在mysql的my.ini(4.0版本的my.ini在c:\windows\下,5.0及以上版本在安装目录下)文件中增加代码

[mysqld]
tmpdir=“新建临时文件夹的路径”

可是后来看自己的mysql5配置,知道虽然tmpdir不存在,但知道mysql有默认的临时文件夹,就是c:\windwos\temp\,可是这个文件夹存在,那为什么还出错哪?

二、

MYSQL+MCAfee竟然有冲突

一启动就:

com.atlassian.jira.exception.DataAccessException: java.sql.SQLException: Can't create/write to file 'C:\WINDOWS\TEMP\#sql_a8c_0.MYD' (Errcode: 13)

MYD或者MYI什么的,都是MYSQL的临时文件,不知道为什么会检测这个。

查了一下网上说:

http: //www.customware.net/repository/pages/viewpage.action?pageId=8093734

This startup error can occur if you have "on-access" scanning enabled in your virus protection software. In this case, the on access scanner of McAfee Total Protection was preventing MySQL writing to a temporary file, causing JIRA to slow down during startup and intermediately throw the above exception.

To disable on-access scanning for McAfee Total Protection

Hold Ctrl + Shift and click the "M shield" in the notification area toolbar of Windows
Select Scan Tasks
Select Disable On-access scanner
竟然这么弱智的问题,关了On-Access Scanner还要杀毒软件干嘛!

我测试一下把排除列表里面加入**\*.MYI和**\*.MYD 貌似就没在出国这个问题。

原来我的机器也安装了MCAfee杀毒软件,在此杀毒软件里设置排除项(可是设置排除某个文件夹,我把mysql临时文件夹位置更改后,在这里加入到排除目录里)后,重启mysql和rensin服务,问题暂时解决,是否可以,有待继续观察。