Home » Mysql » mysql: SOURCE error 2?

mysql: SOURCE error 2?

Posted by: admin November 1, 2017 Leave a comment

Questions:

When I tried to source for a particular .sql file, namely 'metropolises.sql' that I created and saved previously from a database, the following error is displayed:

Failed to open file ‘metropolises.sql’, error: 2

Any idea what went wrong?

Answers:

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.

Questions:
Answers:

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

Questions:
Answers:

Related issue I had getting error 2 running source command: filename must not be in quotes even if it contains spaces in name or path to file.

Questions:
Answers:

I first reach to the file

c:\windows>cd c:\akura\Db Scripts

c:\akura\Db Scripts>mysql -u root -p root

mysql>\. EXECUTER_NEW_USER.sql

here EXECUTER_NEW_USER.sql my file name

Questions:
Answers:

I’ve had the same error on Windows.
I solved it with (after on cmd: mysql -u root):

mysql> SOURCE C:/users/xxx/xxxx/metropolises.sql;

Be sure you type the right file path

Questions:
Answers:

On my windows 8.1, and mysql 5.7.9 MySQL Community Server (GPL),
I had to remove the ; after the file path.

This failed: source E:/jokoni/db/Banking/createTables.sql;

This Worked: source E:/jokoni/db/Banking/createTables.sql
(without termination, and forward slashes instead of windows’ backslashes in path)

Questions:
Answers:

May be the file name or path you are used may be incorrect

In my system i created file abcd.sql at c:\

and used command mysql> source c:\abcd.sql Then i got result

Questions:
Answers:

I got this error in mysql command line using this query:

source `db.sql`;

I changed the above to the following to make it work:

source db.sql;

Questions:
Answers:

If you’re on Debian 8 (Jessie) Linux, try to cd into the directory of the 'metropolises.sql'. Run mysql and execute SOURCE ./metropolises.sql;

Basically, try the relative path. I tried this and it works.

Questions:
Answers:

If you are running dockerized MySQL container such as ones from this official Docker Image registry: https://hub.docker.com/_/mysql/ You may encounter this issue as well.

Questions:
Answers:

It’s probably the file path to your file. If you don’t know the exact location of the file you want to use, try to find your file in Finder, then drag the file into Terminal window

mysql> SOURCE dragfilePathHere 

Questions:
Answers:

If you are using vagrant ensure that the file is on the server and then use the path to the file. e.g if the file is stored in the public folder you will have

sql> source /var/www/public/xxx.sql

Where xxx is the name of the file

Questions:
Answers:

Remove spaces in the folder names of the path, It worked for my mac path.

(Eg: change the folder name MySQL Server 5.1 to MySQLServer5.1)

Questions:
Answers:

i have also got the same message when i try to do the operation from mysql console but when i open the command prompt and do the same steps its working well not getting any error
C:\Users\SubhenduD>cd ../

C:\Users>cd ../

C:>cd \xampp\mysql\bin

C:\xampp\mysql\bin>mysql -u -root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 68
Server version: 5.6.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> use balticktravels;

mysql> source balticktravels.sql;

ITS working well. you may check it.