0

I am at the very beginning of mysql, trying to insert data into a new schema called crashcourse. My code is:

use crashcourse;
source /Users/chenxinyu/Downloads/mysql_scripts/create.sql ;
source /Users/chenxinyu/Downloads/mysql_scripts/populate.sql ;

But it turns out that "11:35:24 source /Users/chenxinyu/Downloads/mysql_scripts/create.sql 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 /Users/chenxinyu/Downloads/mysql_scripts/create.sql' at line 1 0.00031 sec", so how can I solve this problem?

  • Does this answer your question? [What is the correct syntax for the SOURCE command in SQL](https://stackoverflow.com/questions/39871649/what-is-the-correct-syntax-for-the-source-command-in-sql) – Tangentially Perpendicular Jun 13 '21 at 03:47

1 Answers1

2

There are a number of commands, including source, that are only recognized by the MySQL command-line client. See https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html

These commands are parsed and handled by that client, and are not sent to the MySQL Server. This makes them different from all other SQL statements, which are sent to the server to be parsed and executed.

Other clients, such as MySQL Workbench, phpmyadmin, and other developer tools, would need to implement support for those special client-side commands themselves. Few of them do.

Likewise when you write code to use the MySQL API in your own applications, unless you pre-check the SQL statement and handle the special client-only commands yourself, they are not supported.

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