简体   繁体   English

如何编写交流程序以连接到MySQL服务器并执行SQL查询?

[英]How to write a c program for connecting to MySQL server and executing an SQL query?

I need to write a C program that connects to a MySQL server and executes an SQL query from a text file having a single query, in linux platform. 我需要在Linux平台上编写一个连接到MySQL服务器并从具有单个查询的文本文件中执行SQL查询的C程序。

I am doing C programming for a while and also have elementary understanding in SQL. 我从事C编程已有一段时间,并且对SQL有基本的了解。

Now my queries: 现在我的查询:

For this what are the packages i need to install in my linux system? 为此,我需要在linux系统中安装哪些软件包?

How can i do this(programming wise)? 我该怎么做(明智的编程)?

Please give me a starting point where i could begin. 请给我一个可以开始的起点。 Sample codes, links of sites covering this topic and other study materials will very helpful. 示例代码,涵盖该主题的网站链接和其他学习材料将非常有帮助。

Thanks in advance 提前致谢

You must install a C compiler and the libmysql development files for your distro. 您必须为发行版安装C编译器和libmysql开发文件。 After that you use the MySQL C API in your code, and link with the appropriate libraries when building. 之后,您可以在代码中使用MySQL C API ,并在构建时与相应的库链接。

I need to write a C program that connects to a MySQL server and executes an SQL query from a text file having a single query, in linux platform. 我需要在Linux平台上编写一个连接到MySQL服务器并从具有单个查询的文本文件中执行SQL查询的C程序。

If this is really all your program needs to do, and nothing else, it is already written ... you can use the mysql client: 如果这确实是您的程序需要做的所有事情,并且没有别的,那么它已经被编写了……您可以使用mysql客户端:

mysql < my_file.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM