mysql - 从 C 程序调用 SQL 查询时出错

标签 mysql c

我要执行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 documentation :

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 the mysql> prompt:

请注意,source 是列出的其中之一。如果您想知道它是如何工作的,请查看 mysql 客户端的源代码。

如果要执行的源包含多个 MySQL 语句,那么您的连接将需要支持 multiple statement execution ,或者您需要自己将 SQL 解析为单独的语句。

关于mysql - 从 C 程序调用 SQL 查询时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57049973/

相关文章:

c - 如何使用未知维度的二维数组?

php - 在没有数据库的情况下使用 Laravel

c - GCC:混合 C/汇编项目 - include 指令

c - 在 C 中播种 If else 条件

c - printf 连续打印

java - 使用java创建mysql表

MySQL AFTER INSERT 触发器 - 使用新值选择 INTO 不起作用

mysql - 查找存储在innodb引擎中的mysql数据库/表

MySql 条件停止脚本执行

c - 引用字符串时的 Printf 函数