我要执行SOURCE data/keyw.sql
来自 C 程序。当我从命令行执行时,此查询工作正常,但在执行 mysql_query(con, "SOURCE data/keyw.sql")
时出现以下错误
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 data/keyw.sql' at line 1
任何帮助将不胜感激。
最佳答案
SOURCE
命令未在 MySQL 服务器上执行。它由 mysql 客户端解释,基本上只是为了方便。
mysql sends each SQL statement that you issue to the server to be executed. There is also a set of commands that mysql itself interprets. For a list of these commands, type
help
or\h
at themysql>
prompt:
请注意,source
是列出的其中之一。如果您想知道它是如何工作的,请查看 mysql 客户端的源代码。
如果要执行的源包含多个 MySQL 语句,那么您的连接将需要支持 multiple statement execution ,或者您需要自己将 SQL 解析为单独的语句。
关于mysql - 从 C 程序调用 SQL 查询时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57049973/