0

I want to use my SQL'book_data2' file from the desktop E drive as a 'SOURCE'. But I am getting an error code 1064 in MySQL workbench. Could you help me for that issue? I am giving the code and action output below.

Code:

SOURCE E:\DataPractice\Practice\book_data2.sql;

Action Output:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SOURCE E:\DataPractice\Practice\book_data2.sql' at line 1 0.000 sec

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • 1
    show the query code ... – ScaisEdge Jan 10 '21 at 17:54
  • Why do you have to stumble in this type of problem? ... You get an error code `1064`? Google it. It shows you have **syntax error**. One step towards solving made. It tells you **at line 1**? Check the line 1 for any syntax error. Another step made ... Ah, it's another problem if you don't understand where the syntax error is. In this case, can you post some of the first lines of your `sql` file? – Ergis Jan 10 '21 at 17:55
  • I have checked in line 1 but not getting any problem. I have already googled it as well but don't understand correctly that's why I have posted. The code is given below line 1. SHOW DATABASES; USE book_shop; SHOW TABLES; SOURCE E:\DataPractice\Practice\book_data2.sql; – Anik Jan 10 '21 at 17:58
  • Does this answer your question? [How do you use MySQL's source command to import large files in windows](https://stackoverflow.com/questions/6163694/how-do-you-use-mysqls-source-command-to-import-large-files-in-windows) – Nae Jan 10 '21 at 18:00
  • @Anik, well good. Then please share some lines from the sql file with us? – Ergis Jan 10 '21 at 18:04
  • I am very new to SQL that's I don't understand it correctly. SQL file first line is to CREATE TABLE books2 ( book_id INT NOT NULL AUTO_INCREMENT, title VARCHAR(100), author_fname VARCHAR(100), author_lname VARCHAR(100), released_year INT, stock_quantity INT, pages INT, PRIMARY KEY(book_id) ); – Anik Jan 10 '21 at 18:06
  • I never knew about `SOURCE` keyword until now. I usually go `\. myfilepath.sql` to run the lines in the SQL file. Optionally first calling `USE my_schema_name;` to determine the schema to be used by the file by default. – Nae Jan 10 '21 at 18:13

1 Answers1

1

There are a number of commands that are supported by the mysql client (that is, the command-line client, not MySQL Workbench), but they are parsed in the client, not sent to the server as SQL statements. The MySQL Server does not recognize these commands.

It can be confusing, but remember both the client and the server may process commands. You just have to read the documentation to learn which commands are in the list of client-only commands:

https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html

(Except USE, which is recognized by both mysql client and server, just to make sure there's an exception to every rule!)

If you want to use MySQL Workbench to "source" an SQL file, in other words load a file, read the SQL commands in that file, and execute them, Workbench does support this action, but they call it Data Import/Restore. It's documented here: https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828