mysql: SOURCE error 2?

Assuming you mean that you are trying to use the source command in order to execute SQL statements from a text file, the error number given appears to be passed through from the POSIX layer.

Therefore, using this resource, we can deduce that the error value of 2 means "no such file or directory".

In short, you got the path wrong.

Try providing an absolute path, as it's not clear what the current working directory will be in the context of your MySQL server. You may be assuming that it's the working directory of your shell, but it's not obvious that we should expect this to be true.


Just use the absolute path of the file and then, instead of using backslashes, use forward slashes.

Example:

with backslashes : source C:\folder1\metropolises.sql
with forward slashes : source C:/folder1/metropolises.sql


IF YOU ARE USING MYSQL INSIDE DOCKER

Note that if you are running MySQL inside docker then you must first copy the dump into your MySQL docker environment. To do that follow the steps below

  1. First, check and copy the container ID for your MySQL docker by:

    sudo docker ps

  2. Copy the SQL dump file into your container using:

    sudo docker cp /path/to/sql/file.sql MysqlDockerID:/

    This will copy the dump file into the docker root folder if you want to copy the file inside any other directory/path inside docker replace the '/' after 'MysqlDockerID:' with the path you want appropriate one.

  3. Now to interact with MySQL inside a running container run the following command:

    sudo docker exec -it MysqlDockerID bin/bash

  4. Now connect to the MySQL using the terminal by:

    mysql -u yourUserName -p

    This will now ask you for the password. Enter the correct password to proceed.

  5. List the databases available by:

    show Databases;

    This will list out the available databases

  6. Assuming your database name where you want to import dump to is 'MyDatabase'. Switch to that using:

    use MyDatabase

  7. Now you can import the file by typing:

    source file.sql

    Remember the above command works if you have copied your file into your root folder (using step 2). If you have copied it to any other path make sure you use that same path instead