Mysql: SOURCE 2 error?

When I tried to create for a specific .sql file, namely the 'metropolises.sql' , which I created and saved earlier from the database, the following error is displayed:

Could not open file "metropolises.sql", error: 2

Any idea what went wrong?

+66
mysql
Feb 04 2018-12-13T00:
source share
21 answers

Assuming that you want to use the source command to execute SQL statements from a text file, the given error number is passed through the POSIX layer.

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

In short, you have the wrong path.

Try to provide an absolute path, as it is not clear which current working directory will be in the context of your MySQL server. You can assume that this is the working directory of your shell, but it is not obvious that we should expect this to be true.

+86
Feb 04 '13 at 9:59
source share

Just use the absolute path of the file, and then use forward instead of using a backslash.

Example:

with backslashes: source C: \ folder1 \ metropolises.sql
with a slash : source C: /folder1/metropolises.sql

+32
Jun 06 '13 at 7:19
source share

Related problem I had an error starting the original command: the file name should not be in quotation marks, even if it contains spaces in the name or path to the file.

+12
Feb 02 '14 at 8:40
source share

This is probably the path to the file. If you do not know the exact location of the file you want to use, try to find the file in Finder, and then drag it to the terminal window.

 mysql> SOURCE dragfilePathHere 
+5
Apr 13 '17 at 5:33 on
source share

I get to the file first

 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 
+4
Feb 04 '14 at 10:48
source share

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

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

Be sure to enter the correct file path

+2
Jun 12 '14 at
source share

If you use vagrant, make sure the file is on the server, and then use the file path. for example, if the file is stored in a shared folder, you will have

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

Where xxx is the file name

+2
Aug 05 '17 at 21:42 on
source share

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

 source `db.sql`; 

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

 source db.sql; 
+1
Jun 29 '15 at 8:58
source share

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

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

This Worked: source E:/jokoni/db/Banking/createTables.sql (without interruption and slashes instead of backward oblique windows on the way)

+1
Nov 25 '15 at 5:22
source share

On my Mac, this is the only solution that worked for me.

stack overflow

 1 - Download the .sql file and remember it location. 2 - Open your mysql from command prompt or terminal. 3 - Create a database with the same name as that of the database present in the .sql file (create database your_database_name) 4 - Now exit out from the mysql command line client 5 - Now try and execute this command => mysql -u your_username -p your_database_name < your_sql_file_with_complete_location example - mysql -u root -p trial < /home/abc/Desktop/trial.sql here my .sql file is named trial and is present in the desktop, the database is also name trial 6 - You should now have your sql file imported to the corresponding mysql database. 
+1
Jan 14 '19 at 3:57
source share

Maybe the file name or the path you are using may be incorrect

On my system, I created the abcd.sql file in c: \

and the mysql> source c:\abcd.sql Then I got the result

0
04 Feb '13 at 10:00
source share

If you are on Debian 8 (Jessie) Linux, try cd in the 'metropolises.sql' directory. Start mysql and do SOURCE ./metropolises.sql;

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

0
Mar 31 '16 at 23:10
source share

If you use a MySQL-based container, for example, from this official Docker Image registry: https://hub.docker.com/_/mysql/ you may encounter this question .

0
May 11 '16 at 15:33
source share

For me, this was because the file was on a shared drive, and for some reason it could not access this path. I cut the file and put it on my local drive along the path without spaces, and it was resolved.

0
Dec 07 '17 at 20:48
source share

I got the same error when I used the source code of the command and gave the path to the sql file by dragging and dropping it.

Then I just needed to remove those single quotes that appeared by default using drag and drop, the space before the file extension, and it worked.

SOLN:

source / home / xyz / file.sql; (path and space before file extension)

0
Jan 24 '18 at 6:41
source share

For Mac users, you can specify the path as:

 source /Users/YOUR_USER_NAME/Desktop/metropolises.sql; 

* I assumed that the file you need is source in your working desktop and the file name is metropolises.sql




If you are typing,

 source metropolises.sql 

then the file will look in the default location,

 /Users/YOUR_USER_NAME/metropolises.sql; 
0
Nov 24 '18 at 6:26
source share

The solution for me was file permissions on Windows. Just give full control of the file to all users and it will work. After importing, return the access rights to what was before.

0
Jan 13 '19 at 10:44
source share

I had a problem on my Mac because there was a space in the name of one of the folders (directories) in the path. By the way, the space was reset \, but mySQL did not understand

0
Apr 18 '19 at 20:05
source share

Solution - 1) Make sure that you are in the root folder of your application. e.g. app / db / schema.sql.

Solution - 2) open / open the folder in your window and drag && to the command line next to the source of the source files (space). e.g. source user /myMAC/app/db/schema.sql

0
Sep 19 '19 at 1:50
source share

I also received the same message when I try from the MySQL console. However, when I open the command line and do the same steps, it works.

 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; 
-one
Sep 12 '16 at 5:40
source share

Remove spaces in path folder names. It worked for my way to mac.

(For example: change the name of the MySQL Server 5.1 folder to MySQLServer5.1)

-2
Mar 10 '15 at 9:16
source share



All Articles