Warning: curl_exec() has been disabled for security reasons in /pub/host/sunboyu/sunboyu/www/wp-includes/http.php on line 1022

Warning: Cannot modify header information - headers already sent by (output started at /pub/host/sunboyu/sunboyu/www/wp-includes/http.php:1022) in /pub/host/sunboyu/sunboyu/www/wp-includes/feed-rss2.php on line 8
一个程序猿 » MYSQL http://www.sunboyu.cn 时光不会倒流,脚步总要前进 Tue, 31 Jan 2012 10:50:34 +0000 http://wordpress.org/?v=2.7 en hourly 1 php和mysql guid的应用 http://www.sunboyu.cn/2011/04/24/php%e5%92%8cmysql-guid%e7%9a%84%e5%ba%94%e7%94%a8.shtml http://www.sunboyu.cn/2011/04/24/php%e5%92%8cmysql-guid%e7%9a%84%e5%ba%94%e7%94%a8.shtml#comments Sun, 24 Apr 2011 11:00:07 +0000 admin http://www.sunboyu.cn/?p=1405

  GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) 。 GUID是一个通过特定算法产生的二进制长度为128位的数字标识符,用于指示产品的唯一性。GUID 主要用于在拥有多个节点、多台计算机的网络或系统中,分配必须具有唯一性的标识符。
  在 Windows 平台上,GUID 广泛应用于微软的产品中,用于标识如如注册表项、类及接口标识、数据库、系统目录等对象。

php中并没有标准的guid,只是有个函数 uniqid() 生成唯一id。而在mysql中有函数生成guid:SELECT UUID()

]]>
http://www.sunboyu.cn/2011/04/24/php%e5%92%8cmysql-guid%e7%9a%84%e5%ba%94%e7%94%a8.shtml/feed
利用udf扩展mysql增加json_object函数 http://www.sunboyu.cn/2011/01/23/%e5%88%a9%e7%94%a8udf%e6%89%a9%e5%b1%95mysql%e5%a2%9e%e5%8a%a0json_object%e5%87%bd%e6%95%b0.shtml http://www.sunboyu.cn/2011/01/23/%e5%88%a9%e7%94%a8udf%e6%89%a9%e5%b1%95mysql%e5%a2%9e%e5%8a%a0json_object%e5%87%bd%e6%95%b0.shtml#comments Sun, 23 Jan 2011 13:47:57 +0000 admin http://www.sunboyu.cn/?p=1378 其实已经有一个成形的mysql json编码的模块 http://www.mysqludf.org/lib_mysqludf_json/index.php

不过我们在使用的过程中,发现这个函数有版本兼容的问题,后看代码,发现它的json加密规则比较麻烦,没拆出来分析,就自己使用一个json类 http://sourceforge.net/projects/cjson/ 重写了一遍json_object函数。

目前在mysql-5.0.22版本上使用基本没问题,但在mysql5.5以上版本会有问题,udf接口格式好像有了变化。

mysql-5.0.22版本给出的例子是c++的代码。使用了extern语法,为了兼容gcc的语法。而我实际使用纯C环境,就抛弃了extern的语法。

udf_json源码下载

  1. file:udf_json.c
  2. #ifdef STANDARD
  3. #include <stdlib .h>
  4. #include <stdio .h>
  5. #include <string .h>
  6. #ifdef __WIN__
  7. typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
  8. typedef __int64 longlong;
  9. #else
  10. typedef unsigned long long ulonglong;
  11. typedef long long longlong;
  12. #endif /*__WIN__*/
  13. #else
  14. #include <my_global .h>
  15. #include <my_sys .h>
  16. #include <m_string .h>
  17. #endif
  18. #include <mysql .h>
  19. #include <ctype .h>
  20. #include <float .h>
  21. #include "cJSON.h"
  22. #ifdef HAVE_DLOPEN
  23. my_bool json_object_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  24. {
  25.   if (args->arg_count < 1)
  26.   {
  27.     strcpy(message,"Wrong arguments to metaphon;  Use the source");
  28.     return 1;
  29.   }
  30.   return 0;
  31. }
  32. void json_object_deinit(UDF_INIT *initid)
  33. {
  34. }
  35. char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
  36. {
  37. cJSON *root;
  38. char *out;
  39. int i = 0;
  40.  
  41. root=cJSON_CreateObject();
  42. for(i = 0;i<args->arg_count;i++)
  43. {
  44. if(args->arg_type[i] == STRING_RESULT)
  45. {
  46.     cJSON_AddStringToObject(root, args->attributes[i], args->args[i]);
  47. }
  48. else if(args->arg_type[i] == INT_RESULT)
  49. {
  50. cJSON_AddNumberToObject(root, args->attributes[i], *((int*)args->args[i])); //函数参数为double型,这里强转int是好使的,纳闷
  51. }
  52. }
  53. out=cJSON_Print(root);
  54.     cJSON_Delete(root);
  55. *length = strlen(out);
  56. return out;
  57. }
  58. #endif /* HAVE_DLOPEN */
  59.  
  60. file:make.sh
  61. #!/bin/sh
  62. gcc -Wall -I/opt/mysql-5.0.22/include/mysql -I. -shared udf_json.c cJSON.c -o lib_mysqludf_json.so
  63. cp -f ./lib_mysqludf_json.so /usr/lib/lib_mysqludf_json.so
  64. service mysqld restart
  65. </float></ctype></mysql></m_string></my_sys></my_global></string></stdio></stdlib>

编译完成,复制so文件至公共库,然后执行以下语句:

  1. drop function json_object;
  2. create function json_object returns string soname 'lib_mysqludf_json.so';

使用 :

  1. SELECT json_object(field1,field2……) AS jsdate FROM table;

PHP调用:

  1. $db = mysql_connect("127.0.0.1:3306","root","123456");
  2. mysql_select_db("test");
  3. $query = mysql_query("SELECT json_object(id,intval,value) FROM test LIMIT 6");
  4. while($row = mysql_fetch_array($query)){
  5.     var_dump(json_decode($row[0],true));
  6. }

结果显示:

array(3) {
["id"]=>
int(2)
["intval"]=>
int(43324)
["value"]=>
string(10) “fdsfdsfdsa”
}
array(3) {
["id"]=>
int(5)
["intval"]=>
int(432432432)
["value"]=>
string(10) “fdsafdsasa”
}

]]>
http://www.sunboyu.cn/2011/01/23/%e5%88%a9%e7%94%a8udf%e6%89%a9%e5%b1%95mysql%e5%a2%9e%e5%8a%a0json_object%e5%87%bd%e6%95%b0.shtml/feed
mysql5.5.8安装笔记 http://www.sunboyu.cn/2011/01/19/mysql558%e5%ae%89%e8%a3%85%e7%ac%94%e8%ae%b0.shtml http://www.sunboyu.cn/2011/01/19/mysql558%e5%ae%89%e8%a3%85%e7%ac%94%e8%ae%b0.shtml#comments Wed, 19 Jan 2011 03:46:42 +0000 admin http://www.sunboyu.cn/?p=1374 mysql5.5.8对于守旧的人绝对是一种惨无人道的蹂躏。

我开始用mysql5.5.8了,被忽悠得天花乱坠,说性能提升,说主从同步迅速……

不过我是专用udf功能的,因为我常用的mysql稳定版本5.0.22官方说有点小bug,使用udf有点问题,被迫升级了5.5.8版本。

mysql5.5.8抛弃了我们钟爱的configure,而次用了cmake。

当然你要先安装cmake http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz

cmake安装简单,tar后make && make install 搞定。

mysql5.5.8到官网下载 http://dev.mysql.com/downloads/mirror.php?id=399302#mirrors

tar出来,就找不到configure了,不过官方提供了高仿configure的转换脚本,不过神马都是浮云,自己折腾脚本吧

  1. cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.5.8 \
  2.       -DMYSQL_DATADIR=/opt/mysql-5.5.8/data \
  3.       -DSYSCONFDIR=/opt/mysql-5.5.8/etc \
  4.       -DINSTALL_PLUGINDIR=dir_name=/opt/mysql-5.5.8/plugin \
  5.       -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  6.       -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
  7.       -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  8.       -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  9.       -DWITH_PARTITION_STORAGE_ENGINE=1 \
  10.       -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
  11.       -DMYSQL_TCP_PORT=3306 \
  12.       -DENABLED_LOCAL_INFILE=1 \
  13.       -DEXTRA_CHARSETS=all \
  14.       -DDEFAULT_CHARSET=utf8 \
  15.       -DDEFAULT_COLLATION=utf8-general_ci \
  16.       -DMYSQL_USER=mysql

然后make && make install就行。

剩下的事情就跟老版本的一样了,不过我编译的时候没有成功安装 mysql_install_db 脚本,自己写了一个,也算成功完成任务了。

]]>
http://www.sunboyu.cn/2011/01/19/mysql558%e5%ae%89%e8%a3%85%e7%ac%94%e8%ae%b0.shtml/feed
使用MYSQL C api操作mysql http://www.sunboyu.cn/2010/10/31/%e4%bd%bf%e7%94%a8mysql-c-api%e6%93%8d%e4%bd%9cmysql.shtml http://www.sunboyu.cn/2010/10/31/%e4%bd%bf%e7%94%a8mysql-c-api%e6%93%8d%e4%bd%9cmysql.shtml#comments Sun, 31 Oct 2010 13:13:06 +0000 admin http://www.sunboyu.cn/?p=1298
#include
#include
#include “mysql.h”

int main(int argc, char **argv)
{
MYSQL mysql, *sock;
MYSQL_RES *res;
MYSQL_FIELD *fd;
MYSQL_ROW row;
char sql[160];
char host[20];
char user[20];
char pass[20];
char data[20];
int i;
if(argc!=6)
{
fprintf(stderr, “Please input you host, username, password, dbname, sql\n\n”);
exit(0);
}
sprintf(host, argv[1]);
sprintf(user, argv[2]);
sprintf(pass, argv[3]);
sprintf(data, argv[4]);
sprintf(sql, argv[5]);
mysql_init(&mysql);
if(!(sock=mysql_real_connect(&mysql, host, user, pass, data, 0, NULL, 0)))
{
fprintf(stderr, “Can’t connect to engine!\n%s\n”, mysql_error(&mysql));
perror(”");
exit(0);
}
if(mysql_query(sock, sql))
{
fprintf(stderr, “Query failed (%s)\n”, mysql_error(sock));
exit(1);
}
if(!(res=mysql_store_result(sock)))
{
fprintf(stderr, “Couldn`t get result from %s\n”, mysql_error(sock));
exit(1);
}
printf(”number of fields returned:%d\n”, mysql_num_fields(res));
while(row=mysql_fetch_row(res))
{
for(i=0;i {
printf("%d:%s ",i,row[i]);
}
printf("\r\n");
}
mysql_free_result(res);
mysql_close(sock);
exit(0);
return 0;
}

编译参数:gcc mysql.c -o mysql -I /usr/include/mysql -L /lib/mysql -lmysqlclient

]]>
http://www.sunboyu.cn/2010/10/31/%e4%bd%bf%e7%94%a8mysql-c-api%e6%93%8d%e4%bd%9cmysql.shtml/feed
撞在墙上的一个思路 http://www.sunboyu.cn/2010/01/16/%e6%92%9e%e5%9c%a8%e5%a2%99%e4%b8%8a%e7%9a%84%e4%b8%80%e4%b8%aa%e6%80%9d%e8%b7%af.shtml http://www.sunboyu.cn/2010/01/16/%e6%92%9e%e5%9c%a8%e5%a2%99%e4%b8%8a%e7%9a%84%e4%b8%80%e4%b8%aa%e6%80%9d%e8%b7%af.shtml#comments Fri, 15 Jan 2010 16:59:49 +0000 admin http://www.sunboyu.cn/?p=1159 今天一天没干别的,没写程序,没玩游戏,除了中午参加公司的一个吹气球比赛得了第一,获得“**公司第一吹”的称号。

一天都在考虑使用完全开源的方案来解决dz sessions表的性能问题。中午大脑极度紧张,以至于撞在关兄的工位,工位几近散架。

在轻度震荡中想到一个优化方案,就是分离sessions表的一些功能,把sessions会话和统计功能分离,并且统计使用异步提交。

这样,如果sessions会话生存期10分钟的量计算,20万人同时在线,sessions会话存memcached,而统计只用少量字段在独立的表中。因为php的sessions操作速度高,而统计信息调用并不是非常频繁,并且查找也是简单的int型查询,速度快,并且也进行memcached缓存。

下午吴同学详细讲述了我们的统计系统的负载和数据量,在大量实际应用的基础上,我的方案应该能很好的实施。

这样算来,连接瓶颈跟存储瓶颈似乎都能解决。明天集中时间实现这个方案。

]]>
http://www.sunboyu.cn/2010/01/16/%e6%92%9e%e5%9c%a8%e5%a2%99%e4%b8%8a%e7%9a%84%e4%b8%80%e4%b8%aa%e6%80%9d%e8%b7%af.shtml/feed
关于discuz的优化纠结 http://www.sunboyu.cn/2010/01/15/%e5%85%b3%e4%ba%8ediscuz%e7%9a%84%e4%bc%98%e5%8c%96%e7%ba%a0%e7%bb%93.shtml http://www.sunboyu.cn/2010/01/15/%e5%85%b3%e4%ba%8ediscuz%e7%9a%84%e4%bc%98%e5%8c%96%e7%ba%a0%e7%bb%93.shtml#comments Fri, 15 Jan 2010 07:23:42 +0000 admin http://www.sunboyu.cn/?p=1155 最近一直在寻找一个开源的方案来解决discuz的性能瓶颈。在做完几个关键表的分表后,sessions表又成了最大的瓶颈。因为页面每次刷新,至少两个sql语句在session表上,究其原因,session表的最大作用在于对用户行为的统计。

曾经尝试过使用php的session,不过支持phpsession的几个sever都不支持条件查询,除非是遍历匹配。这样也不能起到提高性能的作用。

在以上条件下,我寻找了两套方案:ttserver mongodb。

在session表100w数据的测试下,得出以下数据:

连接测试-只测试连接释放
tt:40.0904033184
mysqldb:0.0669066905975

mongodb:226.840053558
mysqldb:0.154407262802

经过一万次的连接测试,同一个脚本中,
ttserver连接耗时 40.09 秒,而mysql连接耗时0.07秒 linux下测试
mongodb 连接耗时 226.8 秒,而mysql连接耗时0.15秒 linux下测试

但是在500次的查询测试中,同一个脚本中,主键查询和索引优化后的复杂查询
mongodb 查询耗时 0.021 秒
mysql 查询耗时 0.123 秒

可以看出,tt和mongo两个功能上完全支持此表优化的数据库,在连接性能上远不如mysql,而web为频繁连接中断的服务,显然并不适合做这项功能。

继续寻找支持此功能的开源方案,欢迎大家提供线索。

]]>
http://www.sunboyu.cn/2010/01/15/%e5%85%b3%e4%ba%8ediscuz%e7%9a%84%e4%bc%98%e5%8c%96%e7%ba%a0%e7%bb%93.shtml/feed
完全缓存discuz论坛数据 http://www.sunboyu.cn/2009/12/06/%e5%ae%8c%e5%85%a8%e7%bc%93%e5%ad%98discuz%e8%ae%ba%e5%9d%9b%e6%95%b0%e6%8d%ae.shtml http://www.sunboyu.cn/2009/12/06/%e5%ae%8c%e5%85%a8%e7%bc%93%e5%ad%98discuz%e8%ae%ba%e5%9d%9b%e6%95%b0%e6%8d%ae.shtml#comments Sun, 06 Dec 2009 14:15:07 +0000 admin http://www.sunboyu.cn/?p=1072 >>> 发帖数/更新时间 ,则有必要做此缓存,此处缓存更新最为频繁,适合做内存缓存,但 更新时间不宜太久,此时间根据首页更新频度确定。 forumdisplay.php 更新频繁,优化策略同上,只是更新频度略低于首页。 viewthread.php 回复更新频繁,内容更新频度低,适合做硬盘缓存。但分页部分不可做缓存,否则…… space.php 更新不频繁,适合做硬盘缓存。 faq.php 做个静态即可。 以上分析只是根据平时维护总结,临时脑子一蹦,未作具体分析,欢迎广大站长讨论试用。版权所有,欢迎盗版。 ]]> 最近一直在琢磨discuz的优化,想出一些数据缓存的策略:

index.php 部分数据已经进行了缓存,但需要全部缓存,只有当 页面刷新数/更新时间 >>>> 发帖数/更新时间 ,则有必要做此缓存,此处缓存更新最为频繁,适合做内存缓存,但 更新时间不宜太久,此时间根据首页更新频度确定。

forumdisplay.php 更新频繁,优化策略同上,只是更新频度略低于首页。

viewthread.php 回复更新频繁,内容更新频度低,适合做硬盘缓存。但分页部分不可做缓存,否则……

space.php 更新不频繁,适合做硬盘缓存。

faq.php 做个静态即可。

以上分析只是根据平时维护总结,临时脑子一蹦,未作具体分析,欢迎广大站长讨论试用。版权所有,欢迎盗版。

]]>
http://www.sunboyu.cn/2009/12/06/%e5%ae%8c%e5%85%a8%e7%bc%93%e5%ad%98discuz%e8%ae%ba%e5%9d%9b%e6%95%b0%e6%8d%ae.shtml/feed
phpmyadmin语句定界符的问题 http://www.sunboyu.cn/2009/11/11/phpmyadmin%e8%af%ad%e5%8f%a5%e5%ae%9a%e7%95%8c%e7%ac%a6%e7%9a%84%e9%97%ae%e9%a2%98.shtml http://www.sunboyu.cn/2009/11/11/phpmyadmin%e8%af%ad%e5%8f%a5%e5%ae%9a%e7%95%8c%e7%ac%a6%e7%9a%84%e9%97%ae%e9%a2%98.shtml#comments Wed, 11 Nov 2009 09:59:50 +0000 admin http://www.sunboyu.cn/?p=1034 用phpmyadmin写触发器的朋友,不知道有没有碰见这个问题:用pma导出的语句,死活倒不进去,mysqldump导出的,也不能用pma倒入。

反正问题多多,很令人头疼。

今天再次碰到这个问题后,偶然发现个问题,就是sql输入框下的一个小的内容:语句定界符。

平时导出sql,语句定界符默认是分号,而编辑触发器的时候,是两个斜杠//。

蹊跷就在这里,导入的时候使用的定界符必须跟倒出时候的定界符保持一致,否则就会出现错误。

问题发现后,老王是相当的高兴啊。

]]>
http://www.sunboyu.cn/2009/11/11/phpmyadmin%e8%af%ad%e5%8f%a5%e5%ae%9a%e7%95%8c%e7%ac%a6%e7%9a%84%e9%97%ae%e9%a2%98.shtml/feed
discuz论坛优化 http://www.sunboyu.cn/2009/11/05/discuz%e8%ae%ba%e5%9d%9b%e4%bc%98%e5%8c%96.shtml http://www.sunboyu.cn/2009/11/05/discuz%e8%ae%ba%e5%9d%9b%e4%bc%98%e5%8c%96.shtml#comments Thu, 05 Nov 2009 10:19:59 +0000 admin http://www.sunboyu.cn/?p=1031 discuz论坛在国内非常流行,用户众多。优秀的用户体验和超强的负载,也赢得了众多的好评。

但discuz毕竟是为中小型网站设计,很容易达到性能的瓶颈。在最近对discuz的改造和表结构的分析,做了以下的探讨,来提升论坛的性能。

第一步,当然就是分表。
技术实力不太强的用户(严重依赖mysql的用户),分表是最直接的做法(当然,有些功能会损失)。

分析一个运营两年的discuz数据库,库表大概是十几个G左右,posts数据表已经几个千万。

首先可以拆分的,就是post表了。根据情况,post表可以分10张,百张,规则可以哈希,也可以阶段自增(分表主键使用tid(帖子id))。分完表,可以看到一排post_**的表,每个表的数据量降到百万以下,速度就无太大影响。

第二个可以拆分的,是threads表,此表分表,可以水平分割方式水平的分割,可以根据论坛版块id进行分表,这样可以使每个表的数据量减小,但这样也损失了一个功能:全站标题检索。

通过以上两个表的改造论坛的承载能力能迅速见长。

底下会讨论高级优化改造得方法,且听下次分解。

]]>
http://www.sunboyu.cn/2009/11/05/discuz%e8%ae%ba%e5%9d%9b%e4%bc%98%e5%8c%96.shtml/feed
mysql触发器管理 http://www.sunboyu.cn/2009/10/14/mysql%e8%a7%a6%e5%8f%91%e5%99%a8%e7%ae%a1%e7%90%86.shtml http://www.sunboyu.cn/2009/10/14/mysql%e8%a7%a6%e5%8f%91%e5%99%a8%e7%ae%a1%e7%90%86.shtml#comments Wed, 14 Oct 2009 12:45:43 +0000 admin http://www.sunboyu.cn/?p=1016 mysql没有一个像mssql的客户端去管理,所以有了PHPMYADMIN,管理mysql不再单纯依靠命令行,但PHPMYADMIN似乎不是那么万能,偶尔也会耍耍版本细节的脾气。

最近使用mysql触发器,不想使用命令行编辑,但phpmyadmin调试缺比较麻烦,原来想的是先建立一个空的触发器,然后修改,后来发现修改迁移问题多的要死,在老王同学的帮助下,经过几个晚上努力,整理出一些规律。

调试的时候,可以在空的触发器上逐条增加语句,一点一点调试,这样很容易定位问题,迅速修改。

迁移的时候,不能直接编辑触发器拷贝里边的代码,我用的phpmyadmin是2.11.9*版本的,生成的代码虽然他自己认,但一迁移就出了问题,我还没去阅读PHPMYADMIN的代码,不知道代码如何产生,但begin end里的内容大致相同,不同的是两头的辅助语句。

两头的内容跟版本密切相关,用mysqldump导出的语句做模板,把过程添加到里边,基本就没什么问题了。

不同版本的语法稍有出入,没有详细总结,总之掌握了调试的方法,解决问题速度就会提升。

使用触发器后,原来十几次的交互,一次就可以解决。我尝试了下出发器和存储过程,发现开发成本都差不多,复杂度也是类似的,所以没有用存储过程。

]]>
http://www.sunboyu.cn/2009/10/14/mysql%e8%a7%a6%e5%8f%91%e5%99%a8%e7%ae%a1%e7%90%86.shtml/feed
mysql5.1触发器小试 http://www.sunboyu.cn/2009/08/25/mysql5-1%e8%a7%a6%e5%8f%91%e5%99%a8%e5%b0%8f%e8%af%95.shtml http://www.sunboyu.cn/2009/08/25/mysql5-1%e8%a7%a6%e5%8f%91%e5%99%a8%e5%b0%8f%e8%af%95.shtml#comments Tue, 25 Aug 2009 14:51:18 +0000 admin http://www.sunboyu.cn/?p=961 我一直以为mysql5.0的触发器好似没那么强大,被一个搞mssql的老大给忽悠了,其实mysql触发器从5.0就变得很强大,当然包括5.1。

这里拿一个demo说事:

  1. DROP TRIGGER IF EXISTS `ucenterhome`.`uchome_doing_test`;
  2. DELIMITER //
  3. CREATE TRIGGER `ucenterhome`.`uchome_doing_test` AFTER INSERT ON `ucenterhome`.`uchome_doing`
  4.  FOR EACH ROW BEGIN
  5.     INSERT INTO uchome_doing_1 SET doid= NEW.doid+3, uid= NEW.uid , username= NEW.username,`from`=NEW.`from`,dateline=NEW.dateline,message=NEW.message,ip=NEW.ip,replynum = NEW.replynum,mood=NEW.mood;   
  6. END
  7. //
  8. DELIMITER ;

每向uchome_doing表中插一条数据,就复制到uchome_dong_1表中一条。

有两个关键字:

  1. OLD  NEW

官方的解释:

The OLD and NEW keywords enable you to access columns in the rows affected by a trigger. (OLD and NEW are not case sensitive.) In an INSERT trigger, only NEW.col_name can be used; there is no old row. In a DELETE trigger, only OLD.col_name can be used; there is no new row. In an UPDATE trigger, you can use OLD.col_name to refer to the columns of a row before it is updated and NEW.col_name to refer to the columns of the row after it is updated.

还有两个关键字

  1. BEFORE AFTER

官方解释

The keyword BEFORE indicates the trigger action time. In this case, the trigger should activate before each row inserted into the table. The other allowable keyword here is AFTER.

]]>
http://www.sunboyu.cn/2009/08/25/mysql5-1%e8%a7%a6%e5%8f%91%e5%99%a8%e5%b0%8f%e8%af%95.shtml/feed
mysql数据抽象层-PDO http://www.sunboyu.cn/2009/08/20/mysql%e6%95%b0%e6%8d%ae%e6%8a%bd%e8%b1%a1%e5%b1%82-pdo.shtml http://www.sunboyu.cn/2009/08/20/mysql%e6%95%b0%e6%8d%ae%e6%8a%bd%e8%b1%a1%e5%b1%82-pdo.shtml#comments Thu, 20 Aug 2009 08:02:02 +0000 admin http://www.sunboyu.cn/?p=953 好久不用PDO了,公司这边有的项目使用PDO,再熟悉一下,继续沿用之前的方法:

没用数据绑定和一些高级的功能,只是实现基础功能。

  1. < ?php
  2. interface DateBaseConnect
  3. {
  4. #数据库连接
  5. public function Connect( $host , $user , $pass , $datebase );
  6. #使用数据库
  7. public function selectDateBase( $datebase );
  8. #执行一个查询
  9. public function query( $sql );
  10. #取得一行
  11. public function fetch( $sql );
  12. #取得所有
  13. public function fetchAll( $sql );
  14. #取得影响行数
  15. public function affectedRow();
  16. #取得结果行数
  17. public function recordCount();
  18. #取得上次插入ID
  19. public function insertID();
  20. #释放资源
  21. public function close();
  22. }
  23. class sPDO implements DateBaseConnect
  24. {
  25. #连接标识
  26. public $handle = false;
  27. #结果标识
  28. public $query;
  29. #查询次数
  30. public $exetime;
  31. #影响行数
  32. public $affectedRows;
  33. #statement
  34. public $statement;
  35. #数据库连接
  36. public function Connect( $host , $user , $pass , $datebase )
  37. {
  38. try
  39. {
  40. $this->handle = new PDO("mysql:dbname=".$datebase.";host=".$host, $user, $pass);
  41. }
  42. catch (PDOException $e)
  43. {
  44.             echo 'Connection failed: ' . $e->getMessage();
  45. }
  46. $this->exetime = 0;
  47. }
  48. #选择数据库
  49. public function selectDateBase( $database )
  50. {
  51.     return true;
  52. }
  53. #执行一个查询
  54. public function query( $sql )
  55. {
  56.     $this->affectedRows = $this->handle->exec( $sql );
  57. $this->exetime++;
  58. return true;
  59. }
  60. #取得一行
  61. public function fetch( $sql )
  62. {
  63. $this->statement = $this->handle->query( $sql );
  64. return $this->statement->fetch(PDO::FETCH_ASSOC);
  65. }
  66. #取得所有
  67. public function fetchAll( $sql )
  68. {
  69. $this->statement = $this->handle->query( $sql );
  70. return $this->statement->fetchAll(PDO::FETCH_ASSOC);
  71. }
  72. #取得影响行数
  73. public function affectedRow()
  74. {
  75. return $this->affectedRows;
  76. }
  77. #取得结果行数
  78. public function recordCount()
  79. {
  80. return $this->statement->rowCount();
  81. }
  82. #取得上次插入ID
  83. public function insertID()
  84. {
  85. $sql = sprintf("SELECT LAST_INSERT_ID() AS id");
  86. $pdostatement = $this->handle->query( $sql );
  87. $rs = $pdostatement->fetch();
  88. return $rs['id'];
  89. }
  90. #释放资源
  91. public function close()
  92. {
  93. unset($this->handle);
  94. }
  95. #析构函数
  96. function __destruct()
  97. {
  98. $this->close();
  99. }
  100. }
  101. #Demo
  102. $db = new sPDO;
  103. $db->Connect( 'localhost' , 'root' , '123456' , 'ucenterhome' );
  104. $rs = $db->fetchAll( "SELECT * FROM uchome_blogfield" );
  105. print_r( $rs );
  106. ?>
]]>
http://www.sunboyu.cn/2009/08/20/mysql%e6%95%b0%e6%8d%ae%e6%8a%bd%e8%b1%a1%e5%b1%82-pdo.shtml/feed
一个备份mysql的脚本,很简单 http://www.sunboyu.cn/2009/07/29/%e4%b8%80%e4%b8%aa%e5%a4%87%e4%bb%bdmysql%e7%9a%84%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%be%88%e7%ae%80%e5%8d%95.shtml http://www.sunboyu.cn/2009/07/29/%e4%b8%80%e4%b8%aa%e5%a4%87%e4%bb%bdmysql%e7%9a%84%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%be%88%e7%ae%80%e5%8d%95.shtml#comments Wed, 29 Jul 2009 13:43:46 +0000 admin http://www.sunboyu.cn/?p=927 帮朋友维护服务器的时候,习惯性得检查各项服务和维护,偶然间发现了这个脚本,冒着被BS的风险分享给大家,希望大家捧个钱场,施舍给老衲几万块钱买套房。

  1. @echo off
  2. C:
  3. CD "C:\Program Files\WinRAR"
  4.  
  5. net stop Mysql
  6. winrar.exe a -ag"-[YYYY-MM-DD-HH-MM-SS]" -k -r -s -ibck -inul "D:\MYSQL备份生成的文件.rar" "E:\bak\data\*.*"
  7. net start Mysql
]]>
http://www.sunboyu.cn/2009/07/29/%e4%b8%80%e4%b8%aa%e5%a4%87%e4%bb%bdmysql%e7%9a%84%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%be%88%e7%ae%80%e5%8d%95.shtml/feed
Linux下APACHE MYSQL PHP FCgid Suexec 配置文档V1.0 http://www.sunboyu.cn/2009/05/22/linux%e4%b8%8bapache-mysql-php-fcgid-suexec-%e9%85%8d%e7%bd%ae%e6%96%87%e6%a1%a3v10.shtml http://www.sunboyu.cn/2009/05/22/linux%e4%b8%8bapache-mysql-php-fcgid-suexec-%e9%85%8d%e7%bd%ae%e6%96%87%e6%a1%a3v10.shtml#comments Fri, 22 May 2009 03:14:12 +0000 admin http://www.sunboyu.cn/?p=716 文档版本:V1.0

启动撰写时间: 2009年05月20日

目的:全面详细介绍LAMP fastcgi方式配置细节,基于之前的自动配置脚本,目的是把更多的细节转达给大家。

需要软件源码:

CentOS4.7

http://centos.ustc.edu.cn/centos/4.7/isos/i386/CentOS-4.7.ServerCD-i386.iso

http://centos.ustc.edu.cn/centos/4.7/isos/x86_64/CentOS-4.7.ServerCD-x86_64.iso

Apache-2.2.9

http://archive.apache.org/dist/httpd/httpd-2.2.9.tar.gz

MYSQL-5.2.6

http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.22.tar.gz

PHP-5.2.6

http://museum.php.net/php5/php-5.2.6.tar.gz

FCGID

http://ncu.dl.sourceforge.net/sourceforge/mod-fcgid/mod_fcgid.2.2.tgz

安装:

第一步:Linux系统安装,同时可以参照我原来的文档

http://www.sunboyu.cn/2008/06/13/centos5%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97%EF%BC%88%E7%AE%80%E5%8D%95%E7%AF%87%EF%BC%89.shtml

视频。我按照最小化进行安装。最后ping百度不通,是因为没有重启,重启后是正常的。从过程可疑看出,我用的vmware进行安装,所以,要根据你实际的网络情况进行调整配置。

Linux Centos 4.7 安装视频(下载)(关闭)

第二步:系统更新,组件安装。

首先更新一下yum源,具体查看这篇日志 http://www.sunboyu.cn/2009/01/07/centos4%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E4%B8%80%E4%BA%9B%E8%84%9A%E6%9C%AC.shtml

升级一下系统:

yum upgrade

安装一些必要的组件:

yum install gcc gcc-c++ gcc4-c++ autoconf gd gd-devel libxml2 libxml2-devel zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel expat expat-devel sqlite sqlite-devel png-devel jpeg-devel libtool libjpeg* libpng* freetype-devel

安装MYSQL-5.0.22

解压mysql

#tar -zxvf mysql-5.0.22.tar.gz

#cd cd mysql-5.0.22

#groupadd mysql

#useradd -g mysql mysql

#./configure –prefix=/opt/mysql-5.0.22 \
–without-debug \
–enable-thread-safe-client \
–with-client-ldflags=-all-static \
–with-mysqld-ldflags=-all-static \
–enable-local-infile \
–enable-largefile \
–with-charset=utf8 \
–with-collation=utf8_unicode_ci \
–with-extra-charsets=complex \
–with-pic \
–with-mysqld-libs \
–with-comment \
–with-query-cache \
–with-bench \
–with-big-tables \
–with-innodb \
–with-mysqld-use=mysql

#make

#make install

#cp ./support-files/my-medium.cnf /etc/my.cnf

#cp ./support-files/mysql.server /etc/init.d/mysqld

#chmod 755 /etc/init.d/mysqld

#/opt/mysql-5.0.22/bin/mysql_install_db –user=mysql &

#echo “/opt/mysql-5.0.22/bin/mysqld_safe –user=mysql &”>>/etc/rc.local

#service mysqld start

#/opt/mysql-5.0.22/bin/mysqladmin -u root password ‘123456′

#cd ..

安装APACHE

#groupadd apache

#useradd -g apache apache

#tar -zxvf httpd-2.2.9.tar.gz

#cd httpd-2.2.9

#./configure –prefix=/opt/httpd-2.2.9 \
–enable-dav \
–enable-dav-fs \
–enable-modules=all \
–enable-mods-shared=all \
–disable-auth-basic \
–enable-include \
–enable-substitute \
–enable-authz-dbm \
–enable-log-config \
–enable-headers \
–enable-setenvif \
–with-ssl \
–enable-static-ab \
–enable-http \
–enable-mime \
–enable-status \
–enable-isapi \
–enable-imagemap \
–enable-actions \
–enable-speling \
–enable-userdir \
–enable-alias \
–enable-vhost-alias \
–enable-dir \
–enable-rewrite \
–enable-dumpio \
–enable-echo \
–enable-so \
–enable-example \
–enable-case-filter \
–enable-substitute \
–enable-log-config \
–enable-logio \
–enable-env \
–with-mpm=worker \
–with-included-apr \
–with-apr \
–with-apr-util \
–with-z \
–enable-proxy \
–enable-proxy-connect \
–enable-proxy-ftp \
–enable-proxy-http \
–enable-proxy-ajp \
–enable-proxy-balancer \
–enable-suexec \
–with-suexec-caller=apache \
–with-suexec-userdir=www \
–with-suexec-docroot=/home \
–with-suexec-uidmin=100 \
–with-suexec-gidmin=100 \
–with-suexec-logfile=/var/log/suexec_log

#make

#make install

#ln -s /opt/httpd-2.2.9/bin/apachectl /etc/init.d/httpd

#cd ..

修改apache配置文件 /opt/httpd-2.2.9/conf/httpd.conf

找到

User daemon
Group daemon

修改为

User apache
Group apache

安装 fcgid

#tar -zxvf mod_fcgid.2.2.tgz

#cd mod_fcgid.2.2

修改Makefile

top_dir = /usr/local/apache2 为 top_dir = /opt/httpd-2.2.9

#make

#make install

#cd ..

修改apache配置文件 httpd.conf

增加 LoadModule fcgid_module modules/mod_fcgid.so

安装PHP,记得增加cgi支持

#tar -zxvf php-5.2.6.tar.gz

#cd php-5.2.6

#./configure –prefix=/opt/php-5.2.6 –with-libxml-dir –enable-cli –enable-cgi –enable-fastcgi –enable-bcmath –enable-force-cgi-redirect –enable-discard-path –enable-path-info-check –with-openssl –with-pcre-regex –enable-calendar –enable-dom –enable-ftp –with-openssl-dir=/usr/local/ssl –enable-gd-jis-conv –enable-hash –with-iconv –enable-json –enable-mbstring –enable-mbregex –enable-pdo –enable-posix –enable-libxml –enable-simplexml –with-sqlite –enable-tokenizer –enable-xmlreader –enable-xmlwriter –enable-sockets –with-zlib –with-freetype-dir –with-gd –with-jpeg-dir=/usr/lib –with-png-dir=/usr/lib –with-mime-magic –with-mysql=/opt/mysql-5.0.22 –with-zlib-dir=/usr/lib/libz.so –with-pdo-mysql=/opt/mysql-5.0.22 –with-pdo-sqlite –enable-posix –enable-soap

#make

#make install

修改apache配置文件httpd.conf

找到

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

修改为

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

修改apache配置文件 conf/extra/httpd-vhosts.conf

删除所有的虚拟主机

现在配置虚拟主机:

所有虚拟主机的组为 vhost

增加一个用户名为sunboyu的虚拟主机

#groupadd vhost

#useradd -g vhost sunboyu

用户主目录默认为 /home/sunboyu

增加两个目录

#mkdir /home/sunboyu/www

#mkdir /home/sunboyu/logs

增加虚拟主机配置文件

SuexecUserGroup sunboyu vhost
ServerAdmin sunboyu@gmail.com
DocumentRoot “/home/sunboyu/www”
ServerName 192.168.0.4
ServerAlias sunboyu.cn
ErrorLog “/home/sunboyu/logs/error_log”
CustomLog “|/opt/httpd-2.2.9/bin/rotatelogs /home/sunboyu/logs/%Y_%m_%d_log 86400 +480″ common

AddHandler fcgid-script .php
#AddHandler cgi-script .pl .cgi
FCGIWrapper /home/sunboyu/php-cgi .php
Options ExecCGI FollowSymLinks
AllowOverride all
Order deny,allow
Allow from all

创建文件 /home/sunboyu/php-cgi 文件内容为

#!/bin/sh
export PHPRC=/home/sunboyu
export PHP_FCGI_CHILDREN=4
export PHP_FCGI_MAX_REQUESTS=5000
exec /opt/php-5.2.6/bin/php-cgi “$@”

#chmod 755 -R /home/sunboyu

#chown sunboyu:vhost -R /home/sunboyu

配置到现在,重启apache

#service httpd restart

在虚拟目录根下 /home/sunboyu/www 下写文件 info.php 内容为 phpinfo() 修改权限为755 用户组为 sunboyu:vhost

现在访问应该是phpinfo的信息。

在写这篇文档的时候,基本是按照数续依次安装。

如果有问题,希望帮忙,请提前修改你服务器root密码,我们可以一起调试。

]]>
http://www.sunboyu.cn/2009/05/22/linux%e4%b8%8bapache-mysql-php-fcgid-suexec-%e9%85%8d%e7%bd%ae%e6%96%87%e6%a1%a3v10.shtml/feed
Python写的数据库备份程序 http://www.sunboyu.cn/2009/04/22/python%e5%86%99%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e7%a8%8b%e5%ba%8f.shtml http://www.sunboyu.cn/2009/04/22/python%e5%86%99%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e7%a8%8b%e5%ba%8f.shtml#comments Tue, 21 Apr 2009 17:55:00 +0000 admin http://www.sunboyu.cn/?p=664 下载地址:mysqlbak

  1. #!/var/opt/python-2.5/bin/python
  2. import os
  3. import time
  4. import MySQLdb
  5.  
  6.  
  7. CFG = {}
  8. CFG['root'] = {}
  9. CFG['root']['hostname'] = 'localhost'
  10. CFG['root']['username'] = 'root'
  11. CFG['root']['password'] = 'test'
  12.  
  13.  
  14. CFG['mysqldump'] = '/opt/mysql-5.0.22/bin/mysqldump'
  15.  
  16. CFG['time'] = time.strftime("%Y-%m-%d", time.localtime(time.time()) )
  17.  
  18. CFG['bakpath'] = '/tmp/' + CFG['time']
  19. CFG['mainbak'] = '/home/sunboyu/databak/' + CFG['time']
  20.  
  21.  
  22. if os.path.exists( CFG['bakpath'] ) == False:
  23.     os.mkdir( CFG['bakpath'] )
  24. if os.path.exists( CFG['mainbak'] ) == False:
  25.     os.mkdir( CFG['mainbak'] )
  26.  
  27. def mysql_database_bak( database ):
  28.     global CFG
  29.     DIR = CFG['bakpath'] + "/" + database
  30.     if os.path.exists( DIR )==False:
  31.         os.mkdir( DIR )
  32.     conn = MySQLdb.connect( host = CFG['root']['hostname'] , user = CFG['root']['username'] , passwd = CFG['root']['password'] , db = database )
  33.     db = conn.cursor()
  34.     sql = "show tables";
  35.     db.execute( sql )
  36.     result = {}
  37.     for recordline in db.fetchall():
  38.         os.system( CFG['mysqldump'] + " --opt  " + database + " " + recordline[0] + " -u" + CFG['root']['username'] + " -p" + CFG['root']['password'] + " > " + DIR + "/" + database + "_" + recordline[0] + ".sql" )
  39.     os.system( "tar cvf " + CFG['bakpath'] + "/" + database + ".tar.gz " +  CFG['bakpath'] + "/" + database )
  40.     os.system( "mv " + CFG['bakpath'] + "/" + database + ".tar.gz " + CFG['mainbak'] + '/' )
  41.  
  42.  
  43. conn = MySQLdb.connect( host = CFG['root']['hostname'] , user = CFG['root']['username'] , passwd = CFG['root']['password'] , db = 'test' )
  44. sql = "show databases";
  45. db = conn.cursor()
  46. db.execute( sql )
  47. result = {}
  48. bigcount = 0
  49. for recordline in db.fetchall():
  50. littlecount = 0
  51. result[bigcount] = {}
  52. for colnum in db.description:
  53.     result[bigcount][colnum[0]] = recordline[littlecount]
  54.     littlecount += 1
  55. bigcount += 1
  56.  
  57.  
  58. for tables in result:
  59.     mysql_database_bak( result[tables]['Database'] )
  60.  
  61. os.system( "rm -rf /tmp/" + CFG['time'] )  #警告 rm -rf 这个命令相当危险,使用一定要谨慎
]]>
http://www.sunboyu.cn/2009/04/22/python%e5%86%99%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e7%a8%8b%e5%ba%8f.shtml/feed
mysql索引优化 http://www.sunboyu.cn/2009/02/15/mysql%e7%b4%a2%e5%bc%95%e4%bc%98%e5%8c%96.shtml http://www.sunboyu.cn/2009/02/15/mysql%e7%b4%a2%e5%bc%95%e4%bc%98%e5%8c%96.shtml#comments Sun, 15 Feb 2009 06:01:09 +0000 admin http://www.sunboyu.cn/?p=568 做复杂的数据报表经常要很多sql语句连续执行,不是超时就是把mysql跑挂。不过现在硬件廉价,这些软件完美得兼容了多核多线程,虽然一个mysql进程负载高,但只占用一个内核,其他的查询依然可以使用其他的内核进行运算,服务器不会整体挂掉。

mysql优化,主要是索引,大量消耗资源的查询一定要做相关索引优化,具体优化思想我是阅读的这本书-http://www.douban.com/subject/3039216/ 里边mysql优化部分讲得非常简洁明了。而对于cpu的优化,就是尽力把整体时间拉开,cpu会比较平稳。具体做法是用sleep把sql语句分隔,这样用时间换取了稳定。当然,有些报表数据一旦作出就不会再变,这时最好把这些数据文本缓存,以后查询只读取文本即可。

]]>
http://www.sunboyu.cn/2009/02/15/mysql%e7%b4%a2%e5%bc%95%e4%bc%98%e5%8c%96.shtml/feed
MYSQL5新特性,分区表 http://www.sunboyu.cn/2008/11/15/mysql5%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%8c%e5%88%86%e5%8c%ba%e8%a1%a8.shtml http://www.sunboyu.cn/2008/11/15/mysql5%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%8c%e5%88%86%e5%8c%ba%e8%a1%a8.shtml#comments Sat, 15 Nov 2008 09:57:03 +0000 admin http://www.sunboyu.cn/?p=385 CU上看了一个介绍mysql5分区表的帖子,很感兴趣,如果有了分区的应用,那么设计数据库结构可以更加紧凑,而在应用上更加灵活,减少了一些不必要的视图,而在速度上也很好的提升。
分区的好处是,在物理上根据规则对表进行分离。
水平分区其实是B树索引物理上又增加了一级,当然要提高检索速度了,因为又多了一个手工索引。
垂直分区,在一些应用上会更加方便,比如discuz程序,帖子标题跟正文都是分离的,目的是降低单表容量,而有了垂直分区,可以在物理上对字段进行分离,而访问的时候又是类似视图的访问,无比爽也!!
目前还没测试分区到底有多少性能潜力可开发,回头用大的数据查询测试一下。
相关资料:http://dev.mysql.com/doc/refman/5.1/zh/partitioning.html

]]>
http://www.sunboyu.cn/2008/11/15/mysql5%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%8c%e5%88%86%e5%8c%ba%e8%a1%a8.shtml/feed
Mysql数据库抽象层操作类 http://www.sunboyu.cn/2008/09/08/mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%bd%e8%b1%a1%e5%b1%82%e6%93%8d%e4%bd%9c%e7%b1%bb.shtml http://www.sunboyu.cn/2008/09/08/mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%bd%e8%b1%a1%e5%b1%82%e6%93%8d%e4%bd%9c%e7%b1%bb.shtml#comments Mon, 08 Sep 2008 06:26:23 +0000 admin http://www.sunboyu.cn/?p=308 DB.InterFace.php

  1. <?php
  2. /*  DB.InterFace.php
  3.  *  DB
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. interface DateBaseConnect
  12. {
  13.     #数据库连接
  14.     public function Connect( $host , $user , $pass , $datebase );
  15. #使用数据库
  16. public function selectDateBase( $datebase );
  17. #执行一个查询
  18. public function Query( $sql );
  19. #取得一行
  20. public function fetchRow( $sql );
  21. #取得所有
  22. public function fetchAll( $sql );
  23. #取得影响行数
  24. public function affectedRow();
  25. #取得结果行数
  26. public function recordCount();
  27. #取得上次插入ID
  28. public function insertID();
  29. #释放资源
  30. public function close();
  31. }
  32. ?>


DB.Mysql.Class.php

  1. <?php
  2. /*  DB.Mysql.Class.php
  3.  *  Mysql
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. require_once(ROOT."/Include/Class/DB.InterFace.php");
  12. class Mysql implements DateBaseConnect
  13. {
  14. #连接标识
  15. public $handle = false;
  16. #结果标识
  17. public $query;
  18. #查询次数
  19. public $exetime;
  20. #数据库连接
  21.     public function Connect( $host , $user , $pass , $datebase )
  22. {
  23. $this->handle = @mysql_connect( $host , $user , $pass , false ) or die("Can't connetc to the DateBse.".mysql_error());
  24. $this->selectDateBase( $datebase );
  25. $this->exetime = 0;
  26. }
  27. #使用数据库
  28. public function selectDateBase( $datebase )
  29. {
  30. @mysql_select_db( $datebase , $this->handle ) or die("Can't select the DateBase".mysql_error());
  31. }
  32. #执行一个查询
  33. public function Query( $sql )
  34. {
  35. $this->query = mysql_query( $sql , $this->handle ) or die("query error".mysql_error());
  36. $this->exetime++;
  37. return true;
  38. }
  39. #取得一行
  40. public function fetchRow( $sql )
  41. {
  42. $this->Query( $sql );
  43. while( $row = mysql_fetch_array( $this->query, MYSQL_ASSOC ) )
  44. {
  45. return $row;
  46.     }
  47. return false;
  48. }
  49. #取得所有
  50. public function fetchAll( $sql )
  51. {
  52. $this->Query( $sql );
  53. $rows = false;
  54. while( $rs = mysql_fetch_array( $this->query, MYSQL_ASSOC ) )
  55. {
  56. $rows[] = $rs;
  57. }
  58. return $rows;
  59. }
  60. #取得影响行数
  61. public function affectedRow()
  62. {
  63. return mysql_affected_rows( $this->query );
  64. }
  65. #取得结果行数
  66. public function recordCount()
  67. {
  68. return mysql_num_rows( $this->query );
  69. }
  70. #取得上次插入ID
  71. public function insertID()
  72. {
  73. return (mysql_insert_id()>0) ? mysql_insert_id() : false;
  74. }
  75. #释放资源
  76. public function close()
  77. {
  78. @mysql_close( $this->handle );
  79. }
  80. #析构函数
  81. /*
  82. function __destruct()
  83. {
  84. $this->close();
  85. }
  86. */
  87. }
  88. ?>

DB.Mysql.Fact.Class.php

  1. <?php
  2. /*  DB.Mysql.Fact.Class.php
  3.  *  Mysql
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. require_once(ROOT."/Include/Class/DB.Mysql.Class.php");
  12. class DB extends Mysql
  13. {
  14.     #插入操作
  15. /*
  16. $array = array(
  17.     'name' = "sunboyu",
  18. 'pass' = "123456"
  19. );
  20. */
  21. function __insert( $array , $table )
  22. {
  23.     $sql = "INSERT INTO {$table} (";
  24.     if(!is_array($array))
  25. {
  26.     die('the array is not a array!');
  27. }
  28. $keys = array_keys( $array );
  29. $sql .= implode( ',' , $keys );
  30. $sql .= ") VALUES (";
  31. foreach( $array as $key=>$value )
  32. {
  33.     if(is_int( $array[$key] ))
  34. {
  35.     $sql .= $array[$key];
  36. }
  37. else if(is_string( $array[$key] ))
  38. {
  39.     $sql .= "'{$array[$key]}'";
  40. }
  41. $sql .= ",";
  42. }
  43. $sql = substr_replace( $sql , "" , -1 );
  44. $sql .= ")";
  45. return $this->Query( $sql );
  46. }
  47. }
  48. ?>
]]>
http://www.sunboyu.cn/2008/09/08/mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%bd%e8%b1%a1%e5%b1%82%e6%93%8d%e4%bd%9c%e7%b1%bb.shtml/feed
Mysql视图应用 http://www.sunboyu.cn/2008/08/28/mysql%e8%a7%86%e5%9b%be%e5%ba%94%e7%94%a8.shtml http://www.sunboyu.cn/2008/08/28/mysql%e8%a7%86%e5%9b%be%e5%ba%94%e7%94%a8.shtml#comments Thu, 28 Aug 2008 12:55:26 +0000 admin http://www.sunboyu.cn/?p=290 mysql视图创建方法,以我的OpenOA为例,创建user表left jion user_info表的视图

CREATE VIEW v_user AS SELECT * FROM user LEFT JOIN user_info ON (user.id = user_info.user_id)

然后查看

mysql>use oa

mysql>show tables

结果显示,v_user是库oa中的一个表。因此我们使用的时候,可以直接使用语句 SELECT * FROM v_user

而这句也就等于 SELECT * FROM user LEFT JOIN user_info ON (user.id = user_info.user_id)

而实习在系统中,v_user 只有这么一个文件v_user.frm  也就是只有结构,没有数据和索引.打开后,可以看到详细的存储的内容

TYPE=VIEW
query=select `oa`.`user`.`id` AS `id`,`oa`.`user`.`username` AS `username`,`oa`.`user`.`nickname` AS `nickname`,`oa`.`user`.`password` AS `password`,`oa`.`user`.`lastlogintime` AS `lastlogintime`,`oa`.`user`.`lastloginip` AS `lastloginip`,`oa`.`user`.`loginrand` AS `loginrand`,`oa`.`user_info`.`user_id` AS `user_id`,`oa`.`user_info`.`user_realname` AS `user_realname`,`oa`.`user_info`.`user_sex` AS `user_sex`,`oa`.`user_info`.`user_age` AS `user_age`,`oa`.`user_info`.`user_birthplace` AS `user_birthplace`,`oa`.`user_info`.`user_homeaddress` AS `user_homeaddress`,`oa`.`user_info`.`user_idcard` AS `user_idcard`,`oa`.`user_info`.`user_graduateschool` AS `user_graduateschool`,`oa`.`user_info`.`user_educational` AS `user_educational`,`oa`.`user_info`.`user_graduatetime` AS `user_graduatetime`,`oa`.`user_info`.`user_homephone` AS `user_homephone`,`oa`.`user_info`.`user_cellphone` AS `user_cellphone`,`oa`.`user_info`.`user_workphone` AS `user_workphone`,`oa`.`user_info`.`user_fax` AS `user_fax`,`oa`.`user_info`.`user_email` AS `user_email`,`oa`.`user_info`.`user_oicq` AS `user_oicq`,`oa`.`user_info`.`user_msn` AS `user_msn` from (`oa`.`user` left join `oa`.`user_info` on((`oa`.`user`.`id` = `oa`.`user_info`.`user_id`)))
md5=19f7a28463ad7447c3b4cc5428888fa6
updatable=0
algorithm=0
definer_user=root
definer_host=localhost
suid=1
with_check_option=0
revision=1
timestamp=2008-08-28 11:58:17
create-version=1
source=SELECT * FROM user LEFT JOIN user_info ON ( user.id = user_info.user_id )

都是啥意思,没有深究,只是能根据字面猜出来,如果只是用,到此位置即可。

]]>
http://www.sunboyu.cn/2008/08/28/mysql%e8%a7%86%e5%9b%be%e5%ba%94%e7%94%a8.shtml/feed
使用mysql保存session,并建立在线用户列表 http://www.sunboyu.cn/2008/08/15/%e4%bd%bf%e7%94%a8mysql%e4%bf%9d%e5%ad%98session%ef%bc%8c%e5%b9%b6%e5%bb%ba%e7%ab%8b%e5%9c%a8%e7%ba%bf%e7%94%a8%e6%88%b7%e5%88%97%e8%a1%a8.shtml http://www.sunboyu.cn/2008/08/15/%e4%bd%bf%e7%94%a8mysql%e4%bf%9d%e5%ad%98session%ef%bc%8c%e5%b9%b6%e5%bb%ba%e7%ab%8b%e5%9c%a8%e7%ba%bf%e7%94%a8%e6%88%b7%e5%88%97%e8%a1%a8.shtml#comments Fri, 15 Aug 2008 15:02:21 +0000 admin http://www.sunboyu.cn/?p=280 写OA,使用mysql存储session,这样,是为了获得在线用户的列表,为做一个web im做准备。

首先创建表,注,这里使用了adodb中数据字典的描述方法:

  1. $Session_Fields = "
  2. session_id VARCHAR(100) NOTNULL,
  3. session_value X DEFAULT '',
  4. session_expires I(10) DEFAULT NULL,
  5. userid I(5) DEFAULT NULL
  6. ";
  7. $Session_Tables = array('mysql' => "ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci COMMENT = 'session表'");
  8. $dict = NewDataDictionary(GetDB());
  9. $sqlarray = $dict->CreateTableSQL($_CFG['table']['session'], $Session_Fields, $Session_Tables);
  10. $dict->ExecuteSQLArray($sqlarray);

然后session类:

  1. <?php
  2. /*  Session.Class.php
  3.  *  Session Manager
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 14  sunboyu@gmail.com
  9.  */
  10. class Session
  11. {
  12. var $lifetime;
  13. var $db = null;
  14. function __construct()
  15. {
  16. #return adodb lite connetction
  17. $this->db = GetDB();
  18. }
  19. #open
  20. function open( $savepath , $session_name )
  21. {
  22. $this->lifetime =  get_cfg_var("session.gc_maxlifetime");
  23. return true;
  24. }
  25. #close
  26. function close()
  27. {
  28. return true;
  29. }
  30. #read
  31. function read( $session_id )
  32. {
  33. global $_CFG;
  34. $sql = sprintf("SELECT * FROM %s WHERE session_id = %s",$_CFG['table']['session'],GetSqlString( $session_id ));
  35. $rs = $this->db->Execute( $sql );
  36. if($rs->RecordCount()>0)
  37. {
  38. $result = $rs->fields;
  39. return $result['session_value'];
  40. }
  41. else
  42. {
  43. return null;
  44. }
  45. }
  46. #write
  47. function write( $session_id , $session_value )
  48. {
  49. global $_CFG;
  50. $sql = sprintf("SELECT session_id FROM %s WHERE session_id = %s",$_CFG['table']['session'],GetSqlString( $session_id ));
  51. $rs = $this->db->Execute( $sql );
  52. if($rs->RecordCount()==0)
  53. {
  54. $newsql = sprintf("INSERT INTO %s SET session_id = %s , session_value = %s , session_expires = %d",
  55. $_CFG['table']['session'],
  56. GetSqlString( $session_id ),
  57. GetSqlString( $session_value ),
  58. GetSqlString( $this->lifetime+time() , "int" ));
  59. }
  60. else
  61. {
  62. $newsql = sprintf("UPDATE %s SET session_value = %s , session_expires = %d WHERE session_id = %s",
  63. $_CFG['table']['session'],
  64. GetSqlString( $session_value ),
  65. GetSqlString( $this->lifetime+time() , "int" ),
  66. GetSqlString( $session_id ));
  67. }
  68. return $this->db->Execute( $newsql );
  69. }
  70. #destroy
  71. function destroy( $session_id )
  72. {
  73. global $_CFG;
  74. $delsql = sprintf("DELETE FROM %s WHERE session_id = %s",$_CFG['table']['session'],GetSqlString( $session_id ));
  75. return $this->db->Execute( $delsql );
  76. }
  77. #gc
  78. function gc()
  79. {
  80. global $_CFG;
  81. $gcsql = sprintf("DELETE FROM %s WHERE session_expires < %d",$_CFG['table']['session'],time());
  82. return $this->db->Execute( $gcsql );
  83. }
  84. }
  85. ?>

session机制,之前已经介绍,实现代码如下

  1. $session = new Session();
  2. session_set_save_handler(array(&$session,"open"),
  3. array(&$session,"close"),
  4. array(&$session,"read"),
  5. array(&$session,"write"),
  6. array(&$session,"destroy"),
  7. array(&$session,"gc"));
  8. session_start();

把session与用户id对应,使用以下语句即可

  1. sprintf("UPDATE %s SET userid = %d WHERE session_id = %s",$_CFG['table']['session'],GetSqlString($rs['id'],'int'),GetSqlString(session_id(),'text'))
]]>
http://www.sunboyu.cn/2008/08/15/%e4%bd%bf%e7%94%a8mysql%e4%bf%9d%e5%ad%98session%ef%bc%8c%e5%b9%b6%e5%bb%ba%e7%ab%8b%e5%9c%a8%e7%ba%bf%e7%94%a8%e6%88%b7%e5%88%97%e8%a1%a8.shtml/feed
sunboyu-amp-mod-V1.0 alpha http://www.sunboyu.cn/2008/07/26/sunboyu-amp-mod-v10-alpha.shtml http://www.sunboyu.cn/2008/07/26/sunboyu-amp-mod-v10-alpha.shtml#comments Sat, 26 Jul 2008 05:37:47 +0000 admin http://www.sunboyu.cn/?p=222 重新做了个模块版的,这次apache使用动态编译

sunboyu-amp-isapi-v10-alpha

]]>
http://www.sunboyu.cn/2008/07/26/sunboyu-amp-mod-v10-alpha.shtml/feed
sunboyu-amp-fastcgi-V1.0 Alpha版本发布 http://www.sunboyu.cn/2008/07/24/sunboyu-amp-fastcgi-v10-alpha%e7%89%88%e6%9c%ac%e5%8f%91%e5%b8%83.shtml http://www.sunboyu.cn/2008/07/24/sunboyu-amp-fastcgi-v10-alpha%e7%89%88%e6%9c%ac%e5%8f%91%e5%b8%83.shtml#comments Thu, 24 Jul 2008 06:04:45 +0000 admin http://www.sunboyu.cn/?p=218 sunboyu-amp-fastcgi-v10-alpha

基本都配置完毕了,但整体流程没有彻底自动化,适当的时候会作出stable版本。
# author:sunboyu@gmail.com
# qq:176300676 msn:sunboyu@gmail.com
# http://www.sunboyu.cn

#!/bin/sh
h_path = “/root/”
url=”http://www.sunboyu.cn/sourse/”
install_dir=”/opt/”
mkdir $install_dir

termcap_sourse_name=”termcap-1.3.1″

mysql_sourse_name=”mysql-5.0.22″
mysql_install_dir=$install_dir$mysql_sourse_name

openssl_sourse_name=”openssl-0.9.8g”
openssl_install_dir=$install_dir$openssl_sourse_name

httpd_sourse_name=”httpd-2.2.9″
httpd_install_dir=$install_dir$httpd_sourse_name

fastcgi_sourse_name=”mod_fastcgi-2.4.6″
fastcgi_install_dir=$install_dir$fastcgi_sourse_name

fcgid_sourse_name=”mod_fcgid.2.2″

libxml2_sourse_name=”libxml2-2.6.30″
libxml2_install_dir=$install_dir$libxml2_sourse_name

zlib_sourse_name=”zlib-1.2.3″

jpeg_sourse_name=”jpegsrc.v6b”
jpeg_install_dir=$install_dir$jpeg_sourse_name

libpng_sourse_name=”libpng-1.2.29″
libpng_install_dir=$install_dir$libpng_sourse_name

freetype_sourse_name=”freetype-2.3.7″
freetype_install_dir=$install_dir$freetype_sourse_name

php_sourse_name=”php-5.2.6″
php_install_dir=$install_dir$php_sourse_name

gd_sourse_name=”gd-2.0.36RC1″
gd_install_dir=$install_dir$gd_sourse_name

###MYSQL依赖库
wget ${url}${termcap_sourse_name}”.tar.gz”
tar -zxvf $termcap_sourse_name”.tar.gz”
cd $termcap_sourse_name
./configure
make && make install
cd ..
#rm -rf ${termcap_sourse_name}*
###openssl
wget ${url}${openssl_sourse_name}”.tar.gz”
tar -zxvf $openssl_sourse_name”.tar.gz”
cd $openssl_sourse_name
./Configure –prefix=$openssl_install_dir
make && make install
cd ..
#rm -rf ${openssl_sourse_name}*
###libxml
wget ${url}${libxml2_sourse_name}”.tar.gz”
tar -zxvf $libxml2_sourse_name”.tar.gz”
cd $libxml2_sourse_name
./configure –prefix=$libxml2_install_dir
make && make install
cd ..
#rm -rf ${libxml2_sourse_name}*
###zlib
wget ${url}${zlib_sourse_name}”.tar.gz”
tar -zxvf $zlib_sourse_name”.tar.gz”
cd $zlib_sourse_name
./configure
make && make install
cd ..
cp /usr/lib/libz.so.1 /usr/lib/libz.so
#rm -rf ${zlib_sourse_name}*
###jpeg
wget ${url}${jpeg_sourse_name}”.tar.gz”
tar -zxvf $jpeg_sourse_name”.tar.gz”
cd jpeg-6b
./configure
mkdir /usr/local/man/
mkdir /usr/local/man/man1/
mkdir /usr/local/man/man1/cjpeg/
make && make install
cp /usr/lib/libjpeg.so.62 /usr/lib/libjpeg.so
cp jpeglib.h /usr/include/jpeglib.h
cp jconfig.h /usr/include/jconfig.h
cp jmorecfg.h /usr/include/jmorecfg.h
cp jerror.h /usr/include/jerror.h
cd ..
#rm -rf ${jpeg_sourse_name}.tar.gz
#rm -rf jpeg-6b
###png
wget ${url}${libpng_sourse_name}”.tar.gz”
tar -zxvf $libpng_sourse_name”.tar.gz”
cd $libpng_sourse_name
./configure –prefix=$libpng_install_dir
make && make install
cp png* /usr/include/
cd ..
#rm -rf ${libpng_sourse_name}*
###freetype
wget ${url}${freetype_sourse_name}”.tar.gz”
tar -zxvf $freetype_sourse_name”.tar.gz”
cd $freetype_sourse_name
./configure –prefix=$freetype_install_dir
make && make install
cd ..
#rm -rf ${freetype_sourse_name}*
###GD2
wget ${url}${gd_sourse_name}”.tar.gz”
tar -zxvf $gd_sourse_name”.tar.gz”
cd $gd_sourse_name
./configure –prefix=$gd_install_dir –with-png=/opt/libpng-1.2.29 –with-freetype=/opt/freetype-2.3.7 –with-jpeg=/usr/lib/libjpeg.so
make && make install
cd ..
#rm -rf ${gd_sourse_name}*
###MYSQL
groupadd mysql
useradd -g mysql mysql
wget ${url}${mysql_sourse_name}”.tar.gz”
tar -zxvf $mysql_sourse_name”.tar.gz”
cd $mysql_sourse_name
./configure –prefix=$mysql_install_dir –without-debug –with-unix-socket-path=/tmp/mysql.sock –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-static –enable-local-infile –enable-largefile –with-charset=utf8 –with-pic –with-mysqld-libs –with-comment –with-query-cache –with-bench –with-big-tables –with-innodb –with-mysqld-use=mysql
make && make install
cp ./support-files/my-medium.cnf /etc/my.cnf
cp ./support-files/mysql.server /etc/init.d/mysqld
cd ..
#mkdir $mysql_install_dir/var/
#$mysql_install_dir/bin/mysql_install_db –user=mysql &
#$mysql_install_dir/bin/mysqld_safe –user=mysql &

echo ${mysql_install_dir}”/bin/mysqld_safe –user=mysql &”>>/etc/rc.local
#rm -rf ${mysql_sourse_name}*
###APACHE
wget ${url}${httpd_sourse_name}”.tar.gz”
tar -zxvf $httpd_sourse_name”.tar.gz”
cd $httpd_sourse_name
./configure –prefix=$httpd_install_dir –enable-authz-dbm –enable-log-config –enable-headers –enable-setenvif –with-ssl=$openssl_install_dir –enable-static-ab –enable-http –enable-mime –enable-status –enable-suexec –enable-vhost-alias –enable-dir –enable-rewrite –with-mpm=worker
make && make install
cd ..
ln -s $httpd_install_dir/bin/apachectl /etc/init.d/httpd
echo $httpd_install_dir/bin/apachectl start>>/etc/rc.local
chkconfig –level 345 httpd on
#rm -rf ${httpd_sourse_name}*
###fastcgi
wget ${url}${fastcgi_sourse_name}”.tar.gz”
tar -zxvf $fastcgi_sourse_name”.tar.gz”
cd $fastcgi_sourse_name
sed ’s/\/usr\/local\/apache2/\/opt\/httpd-2.2.9\//g’ Makefile.AP2 > Makefile
make && make install
cd ..
###fcgid
wget ${url}${fcgid_sourse_name}”.tgz”
tar -zxvf $fcgid_sourse_name”.tgz”
cd $fcgid_sourse_name
mv Makefile Makefile.AP2
sed ’s/\/usr\/local\/apache2/\/opt\/httpd-2.2.9\//g’ Makefile.AP2 > Makefile
make && make install
cd ..
echo LoadModule fcgid_module modules/mod_fcgid.so>>$httpd_install_dir/conf/httpd.conf
echo AddHandler fcgid-script .php>>$httpd_install_dir/conf/httpd.conf
echo “FCGIWrapper “${php_install_dir}”/bin/php-cgi .php”>>$httpd_install_dir/conf/httpd.conf
#rm -rf ${fastcgi_sourse_name}*
###PHP
wget ${url}${php_sourse_name}”.tar.gz”
tar -zxvf $php_sourse_name”.tar.gz”
cd $php_sourse_name
cp php.ini-dist php.ini
./configure –prefix=$php_install_dir –with-libxml-dir=$libxml2_install_dir –enable-cli –enable-cgi –enable-fastcgi –enable-force-cgi-redirect –enable-discard-path –enable-path-info-check –with-openssl –with-pcre-regex –enable-calendar –enable-dom –enable-ftp –with-openssl-dir=/usr/local/ssl –enable-gd-jis-conv –enable-hash –with-iconv –enable-json –enable-mbstring –enable-mbregex –enable-pdo –enable-posix –enable-libxml=$xml2_install_dir –enable-simplexml –with-sqlite –enable-tokenizer –enable-xmlreader –enable-xmlwriter –with-zlib –with-freetype-dir=$freetype_install_dir –with-gd=$gd_install_dir –with-jpeg-dir=/usr/lib/libjpeg.so –with-libpng-dir=/opt/libpng-1.2.29/lib/libpng12.so –with-zlib-dir=/usr/lib/libz.so –with-mime-magic –with-mysql=$mysql_install_dir –with-zlib-dir=/usr/lib/libz.so –with-pdo-mysql=$mysql_install_dir –with-pdo-sqlite –enable-posix –enable-soap
make && make install
cp php.ini $php_install_dir/lib/
cd ..
$mysql_install_dir/bin/mysql_install_db –user=mysql &

service httpd start
service mysqld start

]]>
http://www.sunboyu.cn/2008/07/24/sunboyu-amp-fastcgi-v10-alpha%e7%89%88%e6%9c%ac%e5%8f%91%e5%b8%83.shtml/feed
amp自动安装脚本安装部分已经完成 http://www.sunboyu.cn/2008/07/22/amp%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac%e5%ae%89%e8%a3%85%e9%83%a8%e5%88%86%e5%b7%b2%e7%bb%8f%e5%ae%8c%e6%88%90.shtml http://www.sunboyu.cn/2008/07/22/amp%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac%e5%ae%89%e8%a3%85%e9%83%a8%e5%88%86%e5%b7%b2%e7%bb%8f%e5%ae%8c%e6%88%90.shtml#comments Tue, 22 Jul 2008 04:04:41 +0000 admin http://www.sunboyu.cn/?p=207 做个版本存档

myshell_demo

]]>
http://www.sunboyu.cn/2008/07/22/amp%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac%e5%ae%89%e8%a3%85%e9%83%a8%e5%88%86%e5%b7%b2%e7%bb%8f%e5%ae%8c%e6%88%90.shtml/feed
LAMP自动安装脚本 http://www.sunboyu.cn/2008/07/15/lamp%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac.shtml http://www.sunboyu.cn/2008/07/15/lamp%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac.shtml#comments Tue, 15 Jul 2008 15:08:39 +0000 admin http://www.sunboyu.cn/?p=200 mysql,apache的基本搞定了,php的还有很多问题,先放出这些代码,方便自己操作。PHP部分正在调试。

#!/bin/sh
h_path = “/root/”
url=”http://www.sunboyu.cn/sourse/”
install_dir=”/opt/”
mkdir $install_dir

termcap_sourse_name=”termcap-1.3.1″

mysql_sourse_name=”mysql-5.0.22″
mysql_install_dir=$install_dir$mysql_sourse_name

openssl_sourse_name=”openssl-0.9.8g”
openssl_install_dir=$install_dir$openssl_sourse_name

httpd_sourse_name=”httpd-2.2.9″
httpd_install_dir=$install_dir$httpd_sourse_name

fastcgi_sourse_name=”mod_fastcgi-2.4.6″
fastcgi_install_dir=$install_dir$fastcgi_sourse_name

libxml2_sourse_name=”libxml2-2.6.30″
libxml2_install_dir=$install_dir$libxml2_sourse_name

zlib_sourse_name=”zlib-1.2.3″
zlib_install_dir=$install_dir$zlib_sourse_name

jpeg_sourse_name=”jpegsrc.v6b”
jpeg_install_dir=$install_dir$jpeg_sourse_name

libpng_sourse_name=”libpng-1.2.29″
libpng_install_dir=$install_dir$libpng_sourse_name

freetype_sourse_name=”freetype-2.3.7″
freetype_install_dir=$install_dir$freetype_sourse_name

php_sourse_name=”php-5.2.6″
php_install_dir=$install_dir$php_sourse_name

###MYSQL
wget ${url}${termcap_sourse_name}”.tar.gz”
tar -zxvf $termcap_sourse_name”.tar.gz”
cd $termcap_sourse_name
./configure
make && make install
cd ..
rm -rf ${termcap_sourse_name}*

groupadd mysql
useradd -g mysql mysql

wget ${url}${mysql_sourse_name}”.tar.gz”
tar -zxvf $mysql_sourse_name”.tar.gz”
cd $mysql_sourse_name
./configure –prefix=$mysql_install_dir –enable-thread-safe-client –enable-local-infile –enable-largefile –with-charset=utf8 –with-uca –with-gnu-ld –with-pic –with-mysqld-libs –with-comment –with-query-cache –with-bench –with-big-tables –with-innodb –with-mysqld-use=mysql
make && make install
cd ..
rm -rf ${mysql_sourse_name}*

###APACHE

wget ${url}${openssl_sourse_name}”.tar.gz”
tar -zxvf $openssl_sourse_name”.tar.gz”
cd $openssl_sourse_name
./configure –prefix=$openssl_install_dir
make && make install
cd ..
rm -rf ${openssl_sourse_name}*

wget ${url}${httpd_sourse_name}”.tar.gz”
tar -zxvf $httpd_sourse_name”.tar.gz”
cd $httpd_sourse_name
./configure –prefix=$httpd_install_dir –enable-authz-dbm –enable-log-config –enable-headers –enable-setenvif –with-ssl=$openssl_install_dir –enable-static-ab –enable-http –enable-mime –enable-status –enable-suexec –enable-vhost-alias –enable-dir –enable-rewrite –with-mpm=worker
make && make install
cd ..
rm -rf ${httpd_sourse_name}*

wget ${url}${fastcgi_sourse_name}”.tar.gz”
tar -zxvf $fastcgi_sourse_name”.tar.gz”
cd $fastcgi_sourse_name
sed ’s/\/usr\/local\/apache2/\/opt\/httpd-2.2.9\//g’ Makefile.AP2 > Makefile
make && make install
cd ..
rm -rf ${fastcgi_sourse_name}*

###PHP
wget ${url}${libxml2_sourse_name}”.tar.gz”
tar -zxvf $libxml2_sourse_name”.tar.gz”
cd $libxml2_sourse_name
./configure –prefix=$libxml2_install_dir
make && make install
cd ..
rm -rf ${libxml2_sourse_name}*

wget ${url}${zlib_sourse_name}”.tar.gz”
tar -zxvf $zlib_sourse_name”.tar.gz”
cd $zlib_sourse_name
./configure –prefix=$zlib_install_dir
make && make install
cd ..
rm -rf ${zlib_sourse_name}*

wget ${url}${jpeg_sourse_name}”.tar.gz”
tar -zxvf $jpeg_sourse_name”.tar.gz”
cd $jpeg_sourse_name
cp makefile.unix Makefile
make && make install
cd ..
rm -rf ${jpeg_sourse_name}*

wget ${url}${libpng_sourse_name}”.tar.gz”
tar -zxvf $libpng_sourse_name”.tar.gz”
cd $libpng_sourse_name
./configure –prefix=$libpng_install_dir
make && make install
cd ..
rm -rf ${libpng_sourse_name}*

wget ${url}${freetype_sourse_name}”.tar.gz”
tar -zxvf $freetype_sourse_name”.tar.gz”
cd $freetype_sourse_name
./configure –prefix=$freetype_install_dir
make && make install
cd ..
rm -rf ${freetype_sourse_name}*

wget ${url}${php_sourse_name}”.tar.gz”
tar -zxvf $php_sourse_name”.tar.gz”
./php-5.2.6/configure –enable-cli –enable-cgi –enable-fastcgi –enable-force-cgi-redirect –enable-discard-path –enable-path-info-check –with-openssl –with-pcre-regex –enable-calendar –enable-dom –enable-ftp –with-openssl-dir=/usr/local/openssl –enable-gd-jis-conv –enable-hash –with-iconv –enable-json –enable-mbstring –enable-mbregex –enable-pdo –enable-posix –enable-libxml –enable-simplexml –with-sqlite –enable-tokenizer –enable-xmlreader –enable-xmlwriter –with-zlib=/usr/local/zlib –with-freetype-dir=/usr/local/freetype –with-gd –with-jpeg-dir=/usr/lib/libjpeg.so.62.0.0

]]>
http://www.sunboyu.cn/2008/07/15/lamp%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e8%84%9a%e6%9c%ac.shtml/feed
打造全能优化的Linux+Apache+PHP+Mysql服务器(3) http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%883%ef%bc%89.shtml http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%883%ef%bc%89.shtml#comments Tue, 15 Jul 2008 06:30:24 +0000 admin http://www.sunboyu.cn/?p=199 apache部分

先安装openssl

./configure –enable-authz-dbm –enable-log-config –enable-headers –enable-setenvif –with-ssl=/usr/local/ssl  –enable-static-ab –enable-http –enable-mime –enable-status –enable-suexec –enable-vhost-alias –enable-dir –enable-rewrite –with-mpm=worker

fastcgi

cp Makefile.AP2 Makefile
make make install

]]>
http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%883%ef%bc%89.shtml/feed
打造全能优化的Linux+Apache+PHP+Mysql服务器(2) http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%882%ef%bc%89.shtml http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%882%ef%bc%89.shtml#comments Tue, 15 Jul 2008 03:33:13 +0000 admin http://www.sunboyu.cn/?p=197 MYsql的安装

mysql 编译参数
./configure –enable-thread-safe-client –enable-local-infile –enable-largefile –with-charset=utf8  –with-uca –with-gnu-ld –with-pic –with-mysqld-libs –with-comment –with-query-cache –with-bench –with-big-tables –with-innodb –with-mysqld-use=mysql

/usr/local/bin/mysql_install_db

/usr/local/bin/mysqld_safe  –user mysql

如果安装时候有错误提示,也许是缺少这个组件  http://www.sunboyu.cn/sourse/termcap-1.3.1.tar.gz

]]>
http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%882%ef%bc%89.shtml/feed
打造全能优化的Linux+Apache+PHP+Mysql服务器(1) http://www.sunboyu.cn/2008/07/13/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%881%ef%bc%89.shtml http://www.sunboyu.cn/2008/07/13/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%881%ef%bc%89.shtml#comments Sun, 13 Jul 2008 13:05:51 +0000 admin http://www.sunboyu.cn/?p=196 fastcgi   http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
apache2   http://apache.mirror.phpchina.com/httpd/httpd-2.2.9.tar.gz
mysql5    http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz/from/http://mysql.mirrors.arminco.com/
php5      http://cn2.php.net/distributions/php-5.2.6.tar.gz
libxml2
gd-jpeg   ftp://192.48.96.9/graphics/jpeg/jpegsrc.v6b.tar.gz
freetype  http://voxel.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.7.tar.gz
libpng    http://voxel.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.29.tar.gz
zend      http://www.zend.com/download/55

memcached  http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
memcache   http://pecl.php.net/get/memcache-3.0.1.tgz
libevent   http://www.monkey.org/~provos/libevent-1.2a.tar.gz

目前想到的功能大概有这些,想到再加。

目前正在研究每一个组件的性能和参数。

]]>
http://www.sunboyu.cn/2008/07/13/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%881%ef%bc%89.shtml/feed
ADODB数据字典的应用 http://www.sunboyu.cn/2008/07/06/adodb%e6%95%b0%e6%8d%ae%e5%ad%97%e5%85%b8%e7%9a%84%e5%ba%94%e7%94%a8.shtml http://www.sunboyu.cn/2008/07/06/adodb%e6%95%b0%e6%8d%ae%e5%ad%97%e5%85%b8%e7%9a%84%e5%ba%94%e7%94%a8.shtml#comments Sun, 06 Jul 2008 14:14:47 +0000 admin http://www.sunboyu.cn/?p=182 我已经很久没有用adodb了,这次用的adodb lite,除了在查询中多了好多方法外,还发现了数据字典这个功能。

因为adodb是兼容多种数据库的,我们切换数据库的时候当然不想去另一个数据库上去重新简表,但mysql,mssql,sqlite这些库好像都不能互转。

而adodb建立数据字典后,可根据你当前的数据库类型生成相应的sql语句,然后创建数据表,而当我们切换数据库的时候,直接修改数据库类型,然后修改一些关键参数即可实现数据库的切换。

方便的很。

]]>
http://www.sunboyu.cn/2008/07/06/adodb%e6%95%b0%e6%8d%ae%e5%ad%97%e5%85%b8%e7%9a%84%e5%ba%94%e7%94%a8.shtml/feed
ADODB Lite-adodb轻量应用 http://www.sunboyu.cn/2008/07/02/adodb-lite-adodb%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8.shtml http://www.sunboyu.cn/2008/07/02/adodb-lite-adodb%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8.shtml#comments Wed, 02 Jul 2008 15:25:11 +0000 admin http://www.sunboyu.cn/?p=175 原来用ADODB进行开发,效率一直是个不小的问题。虽然他可以兼容多个数据库,但在实际开发中几乎没什么用处。小型项目不会去频繁切换数据库,中大的项目也不会忍受它的速度。

突然发现还有个mini版本的adodb lite,官方这样说的:

A small, fast replacement for ADODB that uses 1/6th of the memory and upto 300% faster while being compatible with ADODB using a subset of the most often used ADODB commands.. Supports Frontbase, MaxDB, MiniSql, MSSQL, MySql, Postgres, SqLite and Sybase.

最近做个小程序,正好用上试试,希望不让我失望。

]]>
http://www.sunboyu.cn/2008/07/02/adodb-lite-adodb%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8.shtml/feed
mysql连接机制笔记 http://www.sunboyu.cn/2008/07/01/mysql%e8%bf%9e%e6%8e%a5%e6%9c%ba%e5%88%b6%e7%ac%94%e8%ae%b0.shtml http://www.sunboyu.cn/2008/07/01/mysql%e8%bf%9e%e6%8e%a5%e6%9c%ba%e5%88%b6%e7%ac%94%e8%ae%b0.shtml#comments Tue, 01 Jul 2008 02:20:04 +0000 admin http://www.sunboyu.cn/?p=167 php连接mysql是通过socket进行连接。mysql没有连接池,很郁闷的事情。

连接分 pconnect connect,connect是每次查询都新建一个连接。pconnect是在同一页面中,所有查询都使用一个连接。

]]>
http://www.sunboyu.cn/2008/07/01/mysql%e8%bf%9e%e6%8e%a5%e6%9c%ba%e5%88%b6%e7%ac%94%e8%ae%b0.shtml/feed
mysqli学习中 http://www.sunboyu.cn/2008/06/28/mysqli%e5%ad%a6%e4%b9%a0%e4%b8%ad.shtml http://www.sunboyu.cn/2008/06/28/mysqli%e5%ad%a6%e4%b9%a0%e4%b8%ad.shtml#comments Sat, 28 Jun 2008 13:47:51 +0000 admin http://www.sunboyu.cn/?p=164 任何系统中,数据库连接都是核心的一个操作。

听说mysqli这个组件不错,学习一下,果然发现不少优秀的地方。

http://www.php.net/manual/zh/ref.mysqli.php

这是官方的手册,做个标记,继续学习。

]]>
http://www.sunboyu.cn/2008/06/28/mysqli%e5%ad%a6%e4%b9%a0%e4%b8%ad.shtml/feed
PHP+MYSQL循环插入1W条记录测试 http://www.sunboyu.cn/2008/06/16/php%ef%bc%8bmysql%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a51w%e6%9d%a1%e8%ae%b0%e5%bd%95%e6%b5%8b%e8%af%95.shtml http://www.sunboyu.cn/2008/06/16/php%ef%bc%8bmysql%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a51w%e6%9d%a1%e8%ae%b0%e5%bd%95%e6%b5%8b%e8%af%95.shtml#comments Mon, 16 Jun 2008 14:55:02 +0000 admin http://www.sunboyu.cn/?p=122 表test,字段 id,content
当id没有设置主键的时候,运行时间为 37.186923027
当id设置成主键的时候,运行时间为 44.7759540081
结论……该睡觉了
有点闲着慌

]]>
http://www.sunboyu.cn/2008/06/16/php%ef%bc%8bmysql%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a51w%e6%9d%a1%e8%ae%b0%e5%bd%95%e6%b5%8b%e8%af%95.shtml/feed