按语:
最近项目在云服务器上 centos6.8,安装了mysql5.5.39 server和client,但C连接不知所措;
后在官网下载了 devel、share 、share-compact三个文件并安装;
https://downloads.mysql.com/archives/community/
参看下面取版本号的例子;
gcc mysqlversion.c -lmysqlclient ,用此命令编译并运行能得到结果。
Mysql client version:50539
*** 2019/3/28修改: gcc mysqlversion.c -L/usr/lib64/mysql -lmysqlclient (安装了5.7.24)
创建测试文件: mysqlVersion.c
[root@iZ23xz8uttcZ test]# vi mysqlVersion.c
写入一下代码:
#include <stdio.h>
#include <mysql/mysql.h>
void mysql_version( void )
{
printf("MySQL client version : %d
",mysql_get_client_version());
}
int main(int argc,char *argv[])
{
mysql_version();
return 0;
}
编译:
[root@iZ23xz8uttcZ test]# gcc -c -I /usr/include/mysql mysqlVersion.c -o mysqlVersion.o
error提示:
找不到“mysql.h”文件。
解决方案:
[root@iZ23xz8uttcZ ~] # rpm -ivh MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
链接:
[root@iZ23xz8uttcZ test]# gcc -l mysqlclient mysqlVersion.o -o mysqlVersion
error提示:
mysqlVersion.o: In function `mysql_version':
mysqlVersion.c:(.text+0x5): undefined reference to `mysql_get_client_version'
collect2: error: ld returned 1 exit status
解决方案:
[root@iZ23xz8uttcZ ~] # rpm -ivh MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm
[root@iZ23xz8uttcZ ~] # rpm -ivh MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm
执行:
[root@iZ23xz8uttcZ test]# ./mysqlVersion
MySQL client version : 50622
转 http://blog.csdn.net/u010587274/article/details/50970375