MySQL Running SQL Script error - [WinError 32] The process cannot access the file because it is being used by another process:

16.1k views Asked by At

Error Image

I am getting an error while running a SQL script to load data. Error is pasted below:

Preparing...
[WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\PRATIK~1\\AppData\\Local\\Temp\\tmpf75l0wi5.cnf'

I have tried uninstalling and installing MySQL several times but nothing is helping.

7

There are 7 answers

0
Mike Lischke On

The sounds like you already had tried that script execution before and stopped it without stopping the mysqld process. So this process (which does the actual import) still holds a file lock on the temporary config file.

Try removing that file and check that all MySQL processes that you don't want are stopped. Then try again.

1
M.rob On

I faced the same issues while trying to run a MySQL script. I tried to find the process in the temp folder and removed it and tried again but the process seems to start again and appears in the temp folder. I could not run the script, however, I found a workaround, instead of running the script try to open it and run it in the query editor.

5
Kushagra On

Just downgrade your MySQL workbench version. In my case I downgraded the version from 8.0.25 to 8.0.20.

0
Nico Andrade On

It seems the actual issue is not related to MySQL itself, but to MySQL Workbench.

The error you're seeing is a generic error coming from Windows itself, not from MySQL. It's unclear how you're running MySQL, for example is it in your localhost, in a Docker environment, or in a remote server.

It seems clear that at least two processes are trying to get an exclusive lock on that temporary file. My guess is that MySQL won't write temporary files to the user folder we're seeing (with your username Pratik).

On Windows, MySQL checks in order the values of the TMPDIR, TEMP, and TMP environment variables. For the first one found to be set, MySQL uses it and does not check those remaining. If none of TMPDIR, TEMP, or TMP are set, MySQL uses the Windows system default, which is usually C:\windows\temp.

Something you can do is to change your MySQL configuration so it uses a specific Temporary path you'll set, restart MySQL and retry running the query. If you see the error contains your new temporary path you've isolated the issue, it is indeed a MySQL problem. If you keep seeing this path you've isolated the issue to MySQL WorkBench.

An alternative approach would be to run the same query from another MySQL client, for example the command-line client mysql; and see if you're getting the same error.

Probably the simpler approach would be to try the queries with dBeaver, another MySQL client, and use that to isolate the issue to either the MySQL server itself or MySQL WorkBench.

0
Akeem Ayinla On

This is a common issue for the upgraded version of MySQL, Try using Open Script instead of Run Script and that seems to clear up the issue.

0
Marcin Kunert On

I've found that it was already reported in the official bug tracker: https://bugs.mysql.com/bug.php?id=104841. I've just checked, and it's still present in MySQL Workbench 8.0.30.

0
trig79 On

Work Around
Do not try to open the SQL file from this tool bar:

enter image description here

Go to Server > Data Import:

enter image description here

  • select import from self-contained file
  • select your target schema
  • then start import (bottom right btn)

enter image description here