gcc 编译多线程文件和含MySql数据库操作文件
gcc 强大的编译器就不作介绍了
linux下用gcc命令编译多线程C程序文件和含有MySql数据库操作文件
1.编译多线程文件
gcc -o mylti_thread.o multi_thread.c -lpthread
其中的multi_thread.c表示源文件,mylti_thread.o表示编译产生的目标文件,-lpthread表示引入多线程库,在《Using the GNU Compiler Collection》gcc 4.30 中关于-lpthread的描述如下:
-lpthread Add support for multithreading using the POSIX threads library. This option sets flags for both the preprocessor and linker. It does not affect the thread safety of object code produced by the compiler or that of libraries supplied with it. These are HP-UX specific flags. 要不然会出现类似以下错误
/tmp/cc20DpmC.o: In function `main':
multi_thread.c:(.text+0x78): undefined reference to `pthread_create'
multi_thread.c:(.text+0xe2): undefined reference to `pthread_create'
multi_thread.c:(.text+0xf6): undefined reference to `pthread_join'
multi_thread.c:(.text+0x10a): undefined reference to `pthread_join'
2.编译MySql数据库操作文件
gcc -o sqltest.o sqltest.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient
或者gcc -o sqltest $(mysql_config --cflags) sqltest.c $(mysql_config --libs)
参见网址 http://blog.163.com/zhangjinqing1234@126/blog/static/30730260200992251411161/
其中的sqltest.c表示源文件,sqltest.o表示编译产生的目标文件,-I表示指定头文件的默认搜索路径,-L表示指定要链接的库,同上面-l,具体可参见网址
http://blog.csdn.net/zhulinfeiba/archive/2009/08/20/4464727.aspx
-I后面的参数/usr/include/mysql可能会因为MySql安装的路径不同而有所改变,在终端输入:whereis mysql,结果如下:
mysql: /usr/bin/mysql /etc/mysql /usr/lib/mysql /usr/include/mysql
/usr/share/mysql /usr/share/man/man1/mysql.1.gz
再cd /usr/include/mysql
,然后 ls
decimal.h my_dir.h mysqld_error.h sql_common.h
errmsg.h my_getopt.h mysql_embed.h &n
相关文档:
1. 连接mysql:
mysql -h 主机地址 -u 用户名 -p
2.退出mysql:exit
3. 修改密码:
mysqlbinmysqladmin -uroot -p(oldpassword) password newpassword
4.增加用户:
添加一个用户test1 密码为ABC;让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入
mysql,然后键入以下命 ......
原理
QueryCache(下面简称QC)是根据SQL语句来cache的。一个SQL查询如果以select开头,那么MySQL服务器将尝试对其使用
QC。每个Cache都是以SQL文本作为key来存的。在应用QC之前,SQL文本不会被作任何处理。也就是说,两个SQL语句,只要相差哪怕是一个字符(例如大小写不一样;多一个空格等),那么这两个SQL将使用不同的一 ......
表:
CREATE TABLE `user` (
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(10) DEFAULT NULL,
`password` varchar(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
其中有数据为:
1 name1 123456
2&nbs ......
net start mysql //启动mysql服务
net stop mysql //停止mysql服务
mysqld-nt --remove //删除mysql后台服务
mysqld-nt --install //安装mysql后台服务
mysqld-nt可以换成mysqld-max-nt或mysqld
mysql -u root ......
今天读到
When should you store serialized objects in the database?
,
其中针对
FriendFeed使用Mysql来存储
作为引题,
建议在考虑此方案时一定要三思。为什么?参考这里
Kiss KISS KISS
. 其实
Schema-Less没有错,但不能什么场景都上此方案,要
分析利弊,减少不必要的应用层复杂度。
文中提到的Serializ ......