0

I got error 2 when exec sql file by dictionary

I tried to exec mysql file on Mac OS at this dictionary: "/Users/kato/Desktop/world_mysql_script.sql"

source /Users/kato/Desktop/world_mysql_script.sql;

Then I got this error: Failed to open file '/Users/kato/Desktop/world_mysql_script.sql', error: 2

Do you have any solution? 1.

Shadow
  • 33,525
  • 10
  • 51
  • 64
Kato
  • 1
  • 3
    You need to use the `mysql` command to run .sql files, not your shell. Also it's unclear what you mean with 'dictionary'. – Evert Jan 25 '23 at 16:01
  • Oh I mean directory. Sorry for the typo. – Kato Jan 25 '23 at 16:27
  • I've already jump into mysql container by the following command with Docker: docker exec -it mysql mysql -u root -p \ Then the full command when I exec mysql command is: mysql> source /Users/kato/Desktop/world_mysql_script.sql; – Kato Jan 25 '23 at 16:29
  • 1
    @Evert source is a mysql cli command to load and execute sql scripts from a file. Based on the error message, the OP is within mysql cli, not just within shell. 2 is an operating system-level error. It means that the tool could not find the file either because the path was incorrect or because the user does not have access to it. – Shadow Jan 25 '23 at 16:31
  • @Shadow Yea, I think the reason is that my command doesn't have access to the local file. Any ideas on how to fix that? – Kato Jan 26 '23 at 05:16
  • @Kato I'm sorry but I need to point out the obvious here: either you need to get access to where the file is stored or you need to get someone to move the file where you have access. Not sure what other revelation you were looking for here... – Shadow Jan 26 '23 at 08:41

1 Answers1

0

Please try to use mysql command.

mysql -u DB_USER -p -h DB_HOST DB_NAME < /Users/kato/Desktop/world_mysql_script.sql
bluestar0505
  • 338
  • 1
  • 14