mysql server5.0使用-凯发k8官方网
已正常安装mysql. 程序: #include"mysql.h" #includestdio.h voidmain() { mysqlmysql,*conn; mysql_res*res; mysql_rowrow; /*mysql_init(*/ conn=mysql_real_connect(nbsp;"localhost","root","haha",0,0,0); mysql_close(conn); } 编译参数 cc-l/usr/loca
已正常安装mysql.
程序:
#include "mysql.h"
#include
void main()
{
mysql mysql, *conn;
mysql_res *res;
mysql_row row;
/* mysql_init(&mysql); */
conn = mysql_real_connect(&mysql, "localhost", "root", "haha",0,0,0);
mysql_close(conn);
}
编译参数
cc -l/usr/local/mysql/lib -i/usr/local/mysql/include -o test test.c -lmysqlclient
出错:
undefined first referenced
symbol in file
mysql_real_connect test.o
mysql_close test.o
ld fatal: symbol referencing errors. no output written to test
查不出原因.......... :cry:
cnl 回复于:2004-10-09 17:21:34# l /usr/local/mysql/lib 确认库名是否正确
# grep mysql_real_connect /usr/local/mysql/include/*.h 确认头文件名是否无误
mysql *mysql_real_connect(mysql *mysql, const char *host, const char *user,
const char *passwd, const char *db, uint port, const char *unix_socket,
uint client_flag)
你是否少一个入参啊?
sundy001 回复于:2004-10-09 17:27:43已查证库名及头文件无误,函数已在头文件定义.
请教各位了..
cnl 回复于:2004-10-09 17:31:081、确认入参个数无误
2、把/usr/local/mysql/include及lib的文件名列出来看一下
sundy001 回复于:2004-10-09 17:40:44======库文件====
# cd /usr
# cd local
# cd mysql
# cd lib
# pwd
/opt/k/skunk98/mysql/3.21.26/usr/local/mysql/lib
# ls
libdbug.a
libmygcc.a
libmysqlclient.a
libmystrings.a
libmysys.a
=====头文件=====
# cd ..
# cd include
# ls
config.h
dbug.h
errmsg.h
getopt.h
global.h
hash.h
heap.h
list.h
m_ctype.h
m_string.h
merge.h
my_alarm.h
my_base.h
my_dir.h
my_nosys.h
my_pthread.h
my_sys.h
mysql.h
mysql_com.h
mysql_version.h
mysys_err.h
nisam.h
queues.h
sched.h
thr_alarm.h
thr_lock.h
tree.h
===========mysql.h 部分====
mysql*mysql_real_connect(mysql *mysql, const char *host,
const char *user, const char *passwd,
unsigned int port,const char *unix_socket,
cnl 回复于:2004-10-09 17:51:32[quote:fe115ffb68]
conn = mysql_real_connect(&mysql, "localhost", "root", "haha",0,0,0);
[/quote:fe115ffb68]
你写的入参不够,
sundy001 回复于:2004-10-09 19:14:03不好意思,上贴 粘贴少了. mysql.h 得部分.
mysql *mysql_real_connect(mysql *mysql, const char *host,
const char *user, const char *passwd,
unsigned int port,const char *unix_socket,
unsigned int clientflag);
我引用的:
conn = mysql_real_connect(&mysql, "localhost", "root", "haha",0,0,0);
两边都是7个参数.
lw371 回复于:2004-10-09 19:21:55比mysql资料少一个db参数
不过你这样试一下呢
cc -o test -i/usr/local/mysql/include test.c -l/usr/local/mysql/lib -lmysqlclient
我都是用gcc编译的,没有碰到你的问题:
gcc -o test -i/usr/local/include test.c -l/usr/local/mysql/lib -lmysqlclient -lz
sundy001 回复于:2004-10-09 20:46:36用的是mysql 3,sco openserver 5.0.5安装使用mysql4.0.21的方法windows系统》(https://www.unjs.com)。21。26版本。是少个db参数。
sundy001 回复于:2004-10-10 20:30:24谢谢各位,问题解决了。望今后能多多交流
下面是我的一些操作。希望指正
操作系统:sco openserver 5.0.5
数据库 :mysql 4.0.21
=========== mysql 4.0.21 安装部分 =====================================
软件下载地:
ftp://ftp2.sco.com//pub/skunkware/osr5/vols/
安装:
gzip-1.2.4-vols
fsupthreads-3.5-vols.tar
make-3.78.1-vols.tar
gcc-2.95.2-vols.tar
#cp -p /usr/include/pthread/stdtypes.h /usr/local/lib/gcc-lib/i386-pc-sco3.2v5.0.5/2.95.2/include/pthread/
更改系统搜索路径/.profile为:
path=/usr/local/bin:/bin:/etc:/usr/bin:/tcb/bin
解压mysql-4.0.21.tar.gz
#gzip -d mysql-4.0.21.tar.gz
#tar xvf mysql-4.0.21.tar
#cd mysql-4.0.21
#cflags="-o3 –dsco -mpentium" ldflags=-static cxx=gcc cxxflags="-o3 -dsco -mpentium -felide-constructors"
#./configure --prefix=/usr/local/mysql --with-charset=gb2312 --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --with-named-z-libs=no --disable-shared --without-debug --without-isam --with-innodb
#make
#make install
如出现任何错误需要清理时:
make clean(清除以前make出的文件
make uninstall(反安装)
建立mysql用户和组
建立mysql组 id 100
建立mysql用户 id 200 属mysql组
进入目录/usr/local/mysql/bin
#chown mysql:mysql mysql
进入目录/usr/local
#chown mysql:mysql mysql
#su mysql
$cd /usr/local/mysql/bin
$./mysql_install_db
$./mysqld_safe &
进入root用户
#加入搜索目录/.profile为:
path=/usr/local/bin:/bin:/etc:/usr/bin:/tcb/bin:/usr/local/mysql/bin
#ln -s /usr/local/mysql/bin/mysqld_safe /etc/rc2.d/s94mysql
#reboot
=========== ansi c for mysql 4.0.21 编程部分 =====================================
库目录和头文件目录:
/usr/local/mysql/include/mysql
/usr/local/mysql/lib/mysql
编译参数:
gcc -l/usr/local/mysql/lib/mysql -i/usr/local/mysql/include/mysql -o test test.c -lmysqlclient -lsocket -lm
---------------------测试链接程序-----------
#include "mysql.h"
#include
main(){
mysql mysql;
mysql_res *res;
mysql_row row;
char *query;
int t,r;
/*初始化数据库连接句柄*/
mysql_init(&mysql);
/*建立数据库连接*/
if (!mysql_real_connect(&mysql,"localhost","sundy",
"haha","data",0,null,0))
{
printf( "error connecting to database: %s\n",mysql_error(&mysql));
}
else printf("connected...\n");
/*构造sql查询语句*/
query="select * from data order by dataid desc";
/*执行查询*/
t=mysql_real_query(&mysql,query,(unsigned int) strlen(query));
if (t)
{
printf("error making query: %s\n",
mysql_error(&mysql));
}
else printf("query made...\n");
/*返回记录集*/
res=mysql_use_result(&mysql);
for(r=0;r<=mysql_field_count(&mysql);r ){
row=mysql_fetch_row(res);
if(row<0) break;
for(t=0;tprintf("%s ",row[t]);
}
printf("\n");
}
/*关闭数据库连接*/
mysql_close(&mysql);
}
-----------------------------------------------
lw371 回复于:2004-10-11 14:41:45多谢共享成果!
zhuyuwen 回复于:2004-10-11 16:04:00谢谢
qingxia 回复于:2004-10-12 14:56:07/root/mysql/lib/libmysqlclient.a(my_compress.o)(.text 0xb4): in function `my_compress_alloc':
: undefined reference to `compress'
/root/mysql/lib/libmysqlclient.a(my_compress.o)(.text 0x12a): in function `my_uncompress':
: undefined reference to `uncompress'
collect2: ld returned 1 exit status
这些是什么意思呢?我的机器里是出现这种错误
qingxia 回复于:2004-10-12 14:59:40我的机器是red hat9.0
mysql5.0
代码为
#include
#include
main()
{
mysql mysql;
mysql_init(&mysql);
}
gcc -o test test.c -lmysqlclient -l/root/mysql/lib
原文转自:http://www.ltesting.net
总结
以上是凯发k8官方网为你收集整理的mysql server5.0使用_sco openserver 5.0.5安装使用mysql4.0.21的方法windows系统 -电脑资料...的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: