mysql-cli

Trying to run MySql script gives error "Failed to open file" error: 22, even though the file exists


I have been asked to take over development of a Delphi application that uses MySql 5.7.40. Amongst the information I was given was a dump of the database as an .sql file.

I installed MySql 5.7.40 (although I got version 8.0.31 of some of the related installs), and checked that it all seemed to work.

I then opened up the MySql Command Line Client, and entered the following...

source "C:\Users\Me\Downloads\Dump.sql"

However, this gave an error...

Failed to open file '"C:\Users\Me\Downloads\Dump.sql"', error: 22

I searched around and it seems that this error is caused by either having too many files open, or MySql being out of resources, or MySql not being able to find the file.

The first is unlikely to be the cause, as I am running MySql on a powerful machine with wads of memory, disk space, etc, and have tried restarting the device and doing nothing other than this command.

The only possibility I can see here is that the .sql file is 2Gb, which is maybe why it's running out of resources. However, I'm not sure if there is anything I can do to get around this, as the machine has 64Gb RAM, so any lack of resources is likely to be in MySql itself. Also, I tried creating a very simple .sql file that contained a single command to create a new database, and got the same error, so if it runs out of resources with a file of 35 bytes, then I'm doing something wrong!

The second seems unlikely, as I have checked and rechecked that the file path and name are correct. I've tried it with single and double quotes around the path, as well as both forward and backward slashes. Also, I tried moving my 35 byte .sql file to C:\ and had the same problem.

In case it helps, I'm running on Windows 11 64-bit.

Anyone able to advise? Thanks


Solution

    1. Open a command prompt, and navigate to the folder where the .sql file is stored.

    2. Run mysql - you'll need to make sure the path is in your environment variable. It's probably something like C:\Program Files\MySql\MySql Server 5.7\bin

    3. Try just source Dump.sql (no need for quotes).

    See if that works.