Welcome 微信登录

首页 / 数据库 / MySQL / Linux下C语言进行MySQL数据库操作笔记

vim 编辑模式下可以显示行数“sudo vi /etc/vim/vimrc”在打开的文件中加入“set nu”保存后退出。利用:”vi .bash_history“查看之前输入过的命令编译操作数据库的程序test.c时 输入”./test“提示错误:
Connection error 2002: Can"t connect to local MySQL server through socket "/tmp/mysql.sock" (2)
此时更改mysql下进行数据库连接时的mysql_real_connect(&mysql, "localhost", "localhost", "", "myclink", 0, NULL, 0)其中的第一个localhost换为”127.0.0.1“,记得输入密码”111“编译操作数据库的程序test.c时 输入”./test”提示错误:./test: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory,此时用命令”export“查看环境变量,发现没有mysql的lib的路径,此时输入”vi .bashrc“,在末尾行输入”export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib“将该路径动态添加到环境变量(如果直接在export中间添加,则属于session对话,此时对环境变量的改变属于临时改变,www.linuxidc.com在该对话结束后,环境变量会恢复为以前的状态,而.bashrc在每次编译时会动态执行一次,故可以一次写入,每次调用.bashrc将环境变量添加进去)输入 gcc -o test $(./mysql_config --cflags) test.c $(./mysql_config –libs)
编译时,提示错误信息:
bash: ./mysql_config:
No such file or directorybash: ./mysql_config:
No such file or directorytest.c: In function ‘main’:test.c:36:50:
warning: incompatible implicit declaration of built-in function ‘strlen’/tmp/ccfnwW6I.o:
In function `main":test.c:(.text+0xa9): undefined reference to `mysql_init"test.c:(.text+0xed): undefined reference to `mysql_real_connect"test.c:(.text+0xfd):
undefined reference to `mysql_error"test.c:(.text+0x14f):
undefined reference to `mysql_real_query"test.c:(.text+0x166):
 undefined reference to `mysql_error"test.c:(.text+0x1a2):
undefined reference to `mysql_close"collect2:
 ld returned 1 exit status,
此时将mysql_config复制到程序当前路径下并命名为mysql_config,输入
”cp ./workspace/insert/mysql_config ./mysql_config“
此时”ls“看到当前目录下复制了一个mysql_config文件,
输入 gcc -o test $(./mysql_config --cflags) test.c $(./mysql_config –libs)
再输入”gcc -o test $(./mysql_config --cflags) test.c $(./mysql_config –libs)”
此时在该目录下生成可执行文件testLinux下修改默认MySQL的root管理密码Oracle迁移到DB2(工程部署)问题记述相关资讯      Linux c  MySQL教程 
  • Linux C 内存管理方式之半动态  (08月05日)
  • Linux C语言中gotoxy函数  (04月11日)
  • Linux系统中C&Cpp程序开发  (04月01日)
  • Linux C动态内存泄漏追踪方法  (08月04日)
  • 关于Linux下conio头文件的实现  (04月11日)
  • Linux C 实现mysleep函数  (03月14日)
本文评论 查看全部评论 (0)
表情: 姓名: 字数