虽然是个简单的概念,不过一写成洋文,就变得不容易理解了。

阅读全文

date测试的时候容易出现如下情况,data-s 查询了下,可以实现如下,
date -s "2010-1-1 16:11:21"

但是其他同事也用到date("Y-m-d H:i:s"),就会说:我在调试c程序,是谁修改了服务器时间?我说:我在测试。
于是就有人说没有必要通过date -s来修改整个服务器的时间,而是重写php的该date函数,但是我一旦重写,会提示错误的。
于是又有人说可以关闭掉,date()函数,于是查了下国外的,如下:

Q. I run a small Apache based webserver for my personal use and it is shared with friends and family. However, most script kiddie try to exploit php application such as wordpress using exec() , passthru() , shell_exec() , system() etc functions. How do I disable these functions to improve my php script security?

A. PHP has a lot of functions which can be used to crack your server if not used properly. You can set list of functions in php.ini using disable_functions directive. This directive allows you to disable certain functions for security reasons. It takes on a comma-delimited list of function names. disable_functions is not affected by Safe Mode. This directive must be set in php.ini For example, you cannot set this in httpd.conf.


Open php.ini file:
# vi /etc/php.ini
Find disable_functions and set new list as follows:
disable_functions =exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source !

Save and close the file. Restart httpd:
# service httpd restart



Warning: date() has been disabled for security reasons in  /*/*/datetest.php on line 5



<?php
function date($str)
{

return "2009-12-11 21:09:35";
}
echo date("Y-m-d H:i:s");

?>

出现:
[/usr/local/tads/htdocs/qdkj/src/view]# php datetest.php

Fatal error: Cannot redeclare date() in /data/*/*/src/view/datetest.php on line 6
I think:
PHP already has a date() function and you cannot overwrite existing functions in this language. Rename your function and it will work. Or wrap it in a class and it will work as well.


于是,我在想啊,现在如果有人在用php的date,我给大家把这个date函数给disable了,大家回不会来找我呢?拭目以待。。。

EOF
^[ \t]*\n
注意\t前有空格符。

下面的操作添加正则表达式,该表达式代表待查找的空行。(技巧提示:空行仅包括空格符、制表符、回车符,且必须以这三个符号之一作为一行的开头,并且以回车符结尾,查找空行的关键是构造代表空行的正则表达式)。

    (1)选择“行首”,则查找内容组合框中出现字符“^”,表示待查找的字符串必须出现在文本中一行的行首,才符合条件。

    (2)选择“范围内的字符”,“^”后增加一对括号“[]”,当前插入点在括号中。括号在正则表达式中表示,文本中的字符匹配括号中任意一个字符即符合查找条件。

    (3)按一下空格键,添加空格符。空格符是空行的一个组成成分。

    (4)选择“制表符”,添加代表制表符的“\t”。

    (5)移动光标,将当前插入点移到“]”之后,然后选择“0或多次匹配”,添加了星号字符“*”。星号表示,其前面的括号“[]”内的空格符或制表符,在一行中出现0个或多个。

    (6)选择“换行”,插入“\n”,表示回车符。

    3.替换内容组合框保持空,表示删除查找到的内容。单击“替换”按钮逐个行删除空行,或单击“全部替换”按钮删除全部空行(注意:EditPlus和UltraEdit均存在全部替换不能一次性完全删除空行的问题,可能是程序BUG,需要多按几次按钮)。

    对于熟悉EditPlus的朋友,可以直接在Find what中输入正则表达式^[ \t]*\n ,注意\t前有空格符
参考来源:
http://info.office.hc360.com/2008/07/11142343729.shtml
**  表示中文:


**1000.txt
**1001.txt
**1002.txt
.
.
.
在Linux下想把中文**去掉,如下:

mv *1001.txt 1001.txt
mv *1002.txt 1002.txt
mv *1003.txt 1003.txt
mv *1004.txt 1004.txt
mv *1005.txt 1005.txt
mv *1006.txt 1006.txt
mv *1007.txt 1007.txt
mv *1008.txt 1008.txt
.
.
.
如何生成如上的语句?
步骤:
1.先出一个统一的文件shell.sh:


mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt


2.用awk命令:

num=1000;
cat shell.sh |awk -F"1000" '{print $1 '$num'+NR $2 '$num'+NR  $3}'


生成如下:

mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
mv *1000.txt 1000.txt
.
.
.

Problem:
------------------------------------------------------------------------------------------------------------------------
比如一个文件为:
a 3
b 2
c 4
a 5
d 1
c 2

我要得到唯一的第一列的总和的前三名
就是
a的和为8
c的和为6
然后再按照和排序
a 8
c 6
b 2
d 1

然后得到前三



Solution:
------------------------------------------------------------------------------------------------------------------------
[root@SGDVG405 zhu]# cat datafile
a 3
b 2
c 4
a 5
d 1
c 2
[root@SGDVG405 zhu]# cat datafile |awk '
{
a[$1] += $2;
}
END{
for(i in a) print i,a[i];}
'
a 8
b 2
c 6
d 1
[root@SGDVG405 zhu]#
最好用sort -k2,2nr 排序

提示:其实 man awk 提供的文档也很详细,不过整理加上中文估计还是可以对初学者有一定帮助的。

awk 用法:awk ‘ pattern {action} ‘

变量名 含义
ARGC 命令行变元个数
ARGV 命令行变元数组
FILENAME 当前输入文件名
FNR 当前文件中的记录号
FS 输入域分隔符,默认为一个空格
RS 输入记录分隔符
NF 当前记录里域个数
NR 到目前为止记录数
OFS 输出域分隔符
ORS 输出记录分隔符

1、
awk ‘/101/’ file 显示文件file中包含101的匹配行。
awk ‘/101/,/105/’ file
awk ‘$1 == 5′ file
awk ‘$1 == “CT”‘ file 注意必须带双引号
awk ‘$1 * $2 >100 ‘ file
awk ‘$2 >5 && $2<=15' file

2、
awk '{print NR,NF,$1,$NF,}' file 显示文件file的当前记录号、域数和每一行的第一个和最后一个域。
awk '/101/ {print $1,$2 + 10}' file 显示文件file的匹配行的第一、二个域加10。
awk '/101/ {print $1$2}' file
awk '/101/ {print $1 $2}' file 显示文件file的匹配行的第一、二个域,但显示时域中间没有分隔符。

3、
df | awk '$4>1000000 ‘ 通过管道符获得输入,如:显示第4个域满足条件的行。

4、
awk -F “|” ‘{print $1}’ file 按照新的分隔符“|”进行操作。
awk ‘BEGIN { FS=”[: \t|]” } {print $1,$2,$3}’ file 通过设置输入分隔符(FS=”[: \t|]”)修改输入分隔符。

Sep=”|”
awk -F $Sep ‘{print $1}’ file 按照环境变量Sep的值做为分隔符。
awk -F ‘[ :\t|]’ ‘{print $1}’ file 按照正则表达式的值做为分隔符,这里代表空格、:、TAB、|同时做为分隔符。
awk -F ‘[][]’ ‘{print $1}’ file 按照正则表达式的值做为分隔符,这里代表[、]

5、
awk -f awkfile file 通过文件awkfile的内容依次进行控制。
cat awkfile /101/{print “\047 Hello! \047″} –遇到匹配行以后打印 ‘ Hello! ‘.\047代表单引号。
{print $1,$2} –因为没有模式控制,打印每一行的前两个域。

6、
awk ‘$1 ~ /101/ {print $1}’ file 显示文件中第一个域匹配101的行(记录)。

7、
awk ‘BEGIN { OFS=”%”} {print $1,$2}’ file 通过设置输出分隔符(OFS=”%”)修改输出格式。

8、
awk ‘BEGIN { max=100 ;print “max=” max} BEGIN 表示在处理任意行之前进行的操作。{max=($1 >max ?$1:max); print $1,”Now max is “max}’ file 取得文件第一个域的最大值。
(表达式1?表达式2:表达式3 相当于:
if (表达式1)
表达式2
else
表达式3
awk ‘{print ($1>4 ? “high “$1: “low “$1)}’ file

9、
awk ‘$1 * $2 >100 {print $1}’ file 显示文件中第一个域匹配101的行(记录)。

10、
awk ‘{$1 == ‘Chi’ {$3 = ‘China’; print}’ file 找到匹配行后先将第3个域替换后再显示该行(记录)。
awk ‘{$7 %= 3; print $7}’ file 将第7域被3除,并将余数赋给第7域再打印。

11、
awk ‘/tom/ {wage=$2+$3; printf wage}’ file 找到匹配行后为变量wage赋值并打印该变量。

12、
awk ‘/tom/ {count++;}
END {print “tom was found “count” times”}’ file END表示在所有输入行处理完后进行处理。

13、
awk ‘gsub(/\$/,”");gsub(/,/,”"); cost+=$4; END {print “The total is $” cost>”filename”}’ file gsub函数用空串替换$和,再将结果输出到filename中。
1 2 3 $1,200.00
1 2 3 $2,300.00
1 2 3 $4,000.00

awk ‘{gsub(/\$/,”");gsub(/,/,”");
if ($4>1000&&$4<2000) c1+=$4;
else if ($4>2000&&$4<3000) c2+=$4;
else if ($4>3000&&$4<4000) c3+=$4;
else c4+=$4; }
END {printf "c1=[%d];c2=[%d];c3=[%d];c4=[%d]\n",c1,c2,c3,c4}"' file
通过if和else if完成条件语句

awk '{gsub(/\$/,"");gsub(/,/,"");
if ($4>3000&&$4<4000) exit;
else c4+=$4; }
END {printf "c1=[%d];c2=[%d];c3=[%d];c4=[%d]\n",c1,c2,c3,c4}"' file
通过exit在某条件时退出,但是仍执行END操作。
awk '{gsub(/\$/,"");gsub(/,/,"");
if ($4>3000) next;
else c4+=$4; }
END {printf “c4=[%d]\n”,c4}”‘ file
通过next在某条件时跳过该行,对下一行执行操作。

14、
awk ‘{ print FILENAME,$0 }’ file1 file2 file3>fileall 把file1、file2、file3的文件内容全部写到fileall中,格式为
打印文件并前置文件名。

15、
awk ‘ $1!=previous { close(previous); previous=$1 }
{print substr($0,index($0,” “) +1)>$1}’ fileall 把合并后的文件重新分拆为3个文件。并与原文件一致。

16、
awk ‘BEGIN {”date”|getline d; print d}’ 通过管道把date的执行结果送给getline,并赋给变量d,然后打印。

17、
awk ‘BEGIN {system(”echo \”Input your name:\\c\”"); getline d;print “\nYour name is”,d,”\b!\n”}’
通过getline命令交互输入name,并显示出来。
awk ‘BEGIN {FS=”:”; while(getline< "/etc/passwd" >0) { if($1~”050[0-9]_”) print $1}}’
打印/etc/passwd文件中用户名包含050x_的用户名。

18、
awk ‘{ i=1;while(i awk '{ for(i=1;i type file|awk -F "/" '
{ for(i=1;i { if(i==NF-1) { printf "%s",$i }
else { printf "%s/",$i } }}' 显示一个文件的全路径。
用for和if显示日期
awk 'BEGIN {
for(j=1;j<=12;j++)
{
flag=0;
printf "\n%d月份\n",j;
for(i=1;i<=31;i++)
{
if (j==2&&i>28) flag=1;
if ((j==4||j==6||j==9||j==11)&&i>30) flag=1;
if (flag==0) {printf “%02d%02d “,j,i}
}
}
}’

19、
在awk中调用系统变量必须用单引号,如果是双引号,则表示字符串
Flag=abcd
awk ‘{print ‘$Flag’}’ 结果为abcd
awk ‘{print “$Flag”}’ 结果为$Flag
who am i 2>/dev/null| awk '{print $1,$NF}'
xiangdong (10.65.1.154)
"NF" 代表 Awk 中的一个内置变量,表示当前记录(行)中的字段数(即列数)。在这种上下文中,"NF" 的值表示当前行中的最后一个字段的索引。通过 "$NF",你可以引用当前行中的最后一个字段的值。
who am i
xiangdong pts/1        2023-08-15 15:06 (10.65.1.154)


刚看了SHELL中的awk部分
现在想过滤文件中的空行输出
自己写的两个:
awk '{if($0 !~/^$/)print $0}' test.txt
awk '{if(NF>0)print $0}' test.txt
试了下,可以输出正确结果,但不知道完善不完善或是大家有没有更好的命令


awk '!/^$/' urfile

awk 'NF' urfile

awk '/./' test
awk '!/^$/'  218_219_test.txt


awk 'NF' urfile
真NB!~ 学习·~~
另外两个awk的, 如果有TAB的话不能过滤出去

自己使用:


awk 'NF' 218_219_test.txt


这个简单而且靠谱!阅读全文
经常使用的是:
打日志
Valgrind 使用简单说明  得重点看,还有pc.lint MemCheck 等工具,同时你还可以手动查看,free内存占用情况, ps线程的情况,如内存占用等等。

PC-Lint简介

C/C++语言的语法拥有其它语言所没有的灵活性,这种灵活性带来了代码效率的提升,但相应也使得代码编写具有很大的随意性,另外C/C++编译器不进行强制类型检查,也不做任何边界检查,这就增加了代码中存在隐患的可能性。如果能够在代码提交测试之前发现这些潜在的错误,就能够极大地减轻测试人员的压力,减少软件项目的除错成本,可是传统的C/C++编译器对此已经无能为力,这个任务只能由专用的代码检查工具完成。

PC-Lint是GIMPEL SOFTWARE公司开发的C/C++软件代码静态分析工具,它的全称是PC-Lint/FlexeLint for C/C++,PC-Lint能够在Windows、MS-DOS和OS/2平台上使用,以二进制可执行文件的形式发布,而FlexeLint运行于其它平台,以源代码的形式发布。PC-lint在全球拥有广泛的客户群,许多大型的软件开发组织都把PC-Lint检查作为代码走查的第一道工序。PC-Lint不仅能够对程序进行全局分析,识别没有被适当检验的数组下标,报告未被初始化的变量,警告使用空指针以及冗余的代码,还能够有效地帮你提出许多程序在空间利用、运行效率上的改进点。

http://hi.baidu.com/timegoneby/blog/item/ffaad71790bf060dc93d6dd6.html
http://www.ibm.com/developerworks/cn/linux/l-pow-debug/
Valgrind 介绍

Valgrind是一个GPL的软件,用于Linux(For x86, amd64 and ppc32)程序的内存调试和代码剖析。你可以在它的环境中运行你的程序来监视内存的使用情况,比如C 语言中的malloc和free或者 C++中的new和 delete。使用Valgrind的工具包,你可以自动的检测许多内存管理和线程的bug,避免花费太多的时间在bug寻找上,使得你的程序更加稳固。

Valgrind的主要功能
Valgrind工具包包含多个工具,如Memcheck,Cachegrind,Helgrind, Callgrind,Massif。下面分别介绍个工具的作用:

Memcheck 工具主要检查下面的程序错误:

使用未初始化的内存 (Use of uninitialised memory)
使用已经释放了的内存 (Reading/writing memory after it has been free’d)
使用超过 malloc分配的内存空间(Reading/writing off the end of malloc’d blocks)
对堆栈的非法访问 (Reading/writing inappropriate areas on the stack)
申请的空间是否有释放 (Memory leaks – where pointers to malloc’d blocks are lost forever)
malloc/free/new/delete申请和释放内存的匹配(Mismatched use of malloc/new/new [] vs free/delete/delete [])
src和dst的重叠(Overlapping src and dst pointers in memcpy() and related functions)

Callgrind
Callgrind收集程序运行时的一些数据,函数调用关系等信息,还可以有选择地进行cache 模拟。在运行结束时,它会把分析数据写入一个文件。callgrind_annotate可以把这个文件的内容转化成可读的形式。

Cachegrind
它模拟 CPU中的一级缓存I1,D1和L2二级缓存,能够精确地指出程序中 cache的丢失和命中。如果需要,它还能够为我们提供cache丢失次数,内存引用次数,以及每行代码,每个函数,每个模块,整个程序产生的指令数。这对优化程序有很大的帮助。

Helgrind
它主要用来检查多线程程序中出现的竞争问题。Helgrind 寻找内存中被多个线程访问,而又没有一贯加锁的区域,这些区域往往是线程之间失去同步的地方,而且会导致难以发掘的错误。Helgrind实现了名为” Eraser” 的竞争检测算法,并做了进一步改进,减少了报告错误的次数。

Massif
堆栈分析器,它能测量程序在堆栈中使用了多少内存,告诉我们堆块,堆管理块和栈的大小。Massif能帮助我们减少内存的使用,在带有虚拟内存的现代系统中,它还能够加速我们程序的运行,减少程序停留在交换区中的几率。

Valgrind 安装


转载:【车东的博客】:
http://www.chedong.com/blog/archives/000033.html

最早使用的压力测试工具是apache的ab(apache benchmark),apache ab做重复压力测试不错,但是每次只能测试一个链接,如何测试一组链接(比如从日志中导出的1个小时的日志,做真实压力测试),后来找到了这个:
Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。





SIEGE is an http regressive testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a webserver with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test.

下载/安装
Siege时一个开放源代码项目:http://www.joedog.org

下载:
wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz

安装:
%./configure ; make
#make install

siege包含了一组压力测试工具:
SIEGE (1) Siege是一个HTTP压力测试和评测工具.
使用样例:阅读全文

awk精彩实例

WEB2.0 jackxiang 2009-12-30 12:05
一. 行距:
1. 每行间加一个空行
awk '1; { print "" }' filname.ext          #输出当前行,在输出一个空行
awk '1 { print } { print "" }' filname.ext
awk '{ print } { print "" }' filname.ext

2. 1的另外一种实现方法:
awk 'BEGIN { ORS="\n\n" }; 1' filname.ext #预先设置每一行的分隔符号为两个换行;你可以尝试把ORS设置为其他的看看效果如何

3. 仅输出非空行,并每行间在加一个空行
awk 'NF { print $0 "\n" }' filname.ext    #NF表示当前行的字段数,$0表示当前行,最后再加一个换行
4. 双倍行距;没行间两个空行
awk '1; { print "\n" }' filname.ext     #默认输出后会换行的,输出\n,则会输出两个空白行
等同于:
awk '{ print; print "\n" }' filname.ext


二. 行号和计算
5. 显示当前行在所在文件中的行号
awk '{ print FNR "\t" $0 }' filname.ext    #FNR,表示当前行在文件中的行号

6. 显示当前行在本次处理过程中的行号
awk '{ print NR "\t" $0 }' filname.ext    #NR,表示当前行在本次处理过程中的行号

小疑问:为啥有FNR和NR的差别呢?效果不都是一样么? 如果你给如:filname1.ext filname2.ext,你就会看到差别了。原来:FNR,是每个文件中的,换了一个文件,会归零;而NR则每个文件会累加起来的

7. 使用简单样式来输出
awk '{ printf("%5d : %s\n", NR, $0) }' filname.ext #行号占用5位,不足补空格

8. 显示非空行
awk 'NF { $0=++a " :" $0 }; { print }' filname.ext #NF前面说了,表示当前行的行号,此处用他作为条件,如果是空行,则NF为0,跳过;否则,用动态变量a存储非空行的数目

9. 计算行数:效果类似wc -l
awk 'END { print NR }' filname.ext #END表示每行都处理完了后,在执行,此时NR就是最后一行的行号,也就是总的行数了。

10. 计算每一行的和
awk '{ s = 0; for (i = 1; i <= NF; i++) s = s+$i; print s }' filname.ext
#s用作每行和的累加,从1到NF(每行总的字段数),依次累加
11.   计算文件中所有字段的和
awk '{ for (i = 1; i <= NF; i++) s = s+$i }; END { print s }' filname.ext
#s用作总和的累加,每行都处理完成了,再输出s;注意和10对比,此处没有每行清零,所以累加了。没有设置的变量,默认为空,但是会根据上下文数值计算情况自动变为0

12. 将每个字段用其绝对值代替
awk '{ for (i = 1; i <= NF; i++) if ($i < 0) $i = -$i; print }' filname.ext
#$i表示当前行中的字段,$0表示当前行,可以改变$i的值

13. 计算文件中总的字段和(例如计算单词数)
awk '{ total = total + NF }; END { print total }' filname.ext

14. 计算匹配指定信息的总行数
awk '/Linux/ { n++ }; END { print n+0 }' filname.ext

15. 找到文件中每行第一个字段中,最大的数,以及其所在的行
awk '$1 > max { max=$1; maxline=$0 }; END { print max, maxline }' filname.ext
#用max存储最大的数,maxline存储最大数所在的行,并在最后输出

16. 显示当前行的字段数,并输出当前行
awk '{ print NF ":" $0 } ' filname.ext

17. 显示每行最后一个字段的内容
awk '{ print $NF }' filname.ext #NF表示当前行的字段数,例如为3,则$NF,就是$3,也就是第三个字段了

18. 显示最后一行的最后一个字段
awk '{ field = $NF }; END { print field }' filname.ext
#每行处理没有输出,尽在最后输出,field作为每行的最后一行的暂存变量

19. 显示字段数小于4的行
awk 'NF < 4' filname.ext #{}以外的内容,作为条件,没有{},则默认输出当前行

20. 显示每行的最后一个字段小于4的行
awk '$NF < 4' filname.ext #注意和19对比
Left和date_format函数:
[code]
$sql="select count(*) from Tbl_XXshow_XX where  FXX='$XX' and FCode=2 and left(FTime,7)=left(now(),7)";
select count(*) as c from Tbl_Exchange_XX where FLType=218 and date_format(now(),'%Y-%m-%d')=date_format(FTime,'%Y-%m-%d')
[/code]
select timediff('23:40:00', ' 18:30:00'); -- 两时间相减
SELECT   substring( timediff('23:40:00', ' 18:30:00'),1,5) ----“05:10”相减返回小时:分钟

select datediff('2008-08-08', '2008-08-01'); -- 7      -----两日期相减
select TO_DAYS('2008-09-08')-TO_DAYS('2008-08-08')     -----两日期相减

SELECT   substring( '2009-06-17 10:00:00',   1,   10   )   ----从datetime中提取“日期”


(********************* 时间戳是从1970年1月1日开始到目标时间所经过的秒数.
                                 可以进行两个datetime时间间隔的运算******************************)






一、MySQL 获得当前日期时间 函数
1.1 获得当前日期+时间(date + time)函数:now()
mysql> select now();

+---------------------+
&#124; now() &#124;
+---------------------+
&#124; 2008-08-08 22:20:46 &#124;
+---------------------+

除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数:
current_timestamp()
,current_timestamp
,localtime()
,localtime
,localtimestamp -- (v4.0.6)
,localtimestamp() -- (v4.0.6)

这些日期时间函数,都等同于 now()。鉴于 now() 函数简短易记,建议总是使用 now() 来替代上面列出的函数。
1.2 获得当前日期+时间(date + time)函数:sysdate()
sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。看下面的例子就明白了:
mysql> select now(), sleep(3), now();

+---------------------+----------+---------------------+
&#124; now() &#124; sleep(3) &#124; now() &#124;
+---------------------+----------+---------------------+
&#124; 2008-08-08 22:28:21 &#124; 0 &#124; 2008-08-08 22:28:21 &#124;
+---------------------+----------+---------------------+

mysql> select sysdate(), sleep(3), sysdate();

+---------------------+----------+---------------------+
&#124; sysdate() &#124; sleep(3) &#124; sysdate() &#124;
+---------------------+----------+---------------------+
&#124; 2008-08-08 22:28:41 &#124; 0 &#124; 2008-08-08 22:28:44 &#124;
+---------------------+----------+---------------------+

可以看到,虽然中途 sleep 3 秒,但 now() 函数两次的时间值是相同的; sysdate() 函数两次得到的时间值相差 3 秒。MySQL Manual 中是这样描述 sysdate() 的:Return the time at which the function executes。
sysdate() 日期时间函数,一般情况下很少用到。
2. 获得当前日期(date)函数:curdate()
mysql> select curdate();

+------------+
&#124; curdate() &#124;
+------------+
&#124; 2008-08-08 &#124;
+------------+

其中,下面的两个日期函数等同于 curdate():
current_date()
,current_date

3. 获得当前时间(time)函数:curtime()
mysql> select curtime();

+-----------+
&#124; curtime() &#124;
+-----------+
&#124; 22:41:30 &#124;
+-----------+

其中,下面的两个时间函数等同于 curtime():
current_time()
,current_time

4. 获得当前 UTC 日期时间函数:utc_date(), utc_time(), utc_timestamp()
mysql> select utc_timestamp(), utc_date(), utc_time(), now()

+---------------------+------------+------------+---------------------+
&#124; utc_timestamp() &#124; utc_date() &#124; utc_time() &#124; now() &#124;
+---------------------+------------+------------+---------------------+
&#124; 2008-08-08 14:47:11 &#124; 2008-08-08 &#124; 14:47:11 &#124; 2008-08-08 22:47:11 &#124;
+---------------------+------------+------------+---------------------+

因为我国位于东八时区,所以本地时间 = UTC 时间 + 8 小时。UTC 时间在业务涉及多个国家和地区的时候,非常有用。

二、MySQL 日期时间 Extract(选取) 函数。
1. 选取日期时间的各个部分:日期、时间、年、季度、月、日、小时、分钟、秒、微秒
set @dt = '2008-09-10 07:15:30.123456';

select date(@dt); -- 2008-09-10
select time(@dt); -- 07:15:30.123456
select year(@dt); -- 2008
select quarter(@dt); -- 3
select month(@dt); -- 9
select week(@dt); -- 36
select day(@dt); -- 10
select hour(@dt); -- 7
select minute(@dt); -- 15
select second(@dt); -- 30
select microsecond(@dt); -- 123456

2. MySQL Extract() 函数,可以上面实现类似的功能:
set @dt = '2008-09-10 07:15:30.123456';

select extract(year from @dt); -- 2008
select extract(quarter from @dt); -- 3
select extract(month from @dt); -- 9
select extract(week from @dt); -- 36
select extract(day from @dt); -- 10
select extract(hour from @dt); -- 7
select extract(minute from @dt); -- 15
select extract(second from @dt); -- 30
select extract(microsecond from @dt); -- 123456

select extract(year_month from @dt); -- 200809
select extract(day_hour from @dt); -- 1007
select extract(day_minute from @dt); -- 100715
select extract(day_second from @dt); -- 10071530
select extract(day_microsecond from @dt); -- 10071530123456
select extract(hour_minute from @dt); -- 715
select extract(hour_second from @dt); -- 71530
select extract(hour_microsecond from @dt); -- 71530123456
select extract(minute_second from @dt); -- 1530
select extract(minute_microsecond from @dt); -- 1530123456
select extract(second_microsecond from @dt); -- 30123456

MySQL Extract() 函数除了没有date(),time() 的功能外,其他功能一应具全。并且还具有选取‘day_microsecond’ 等功能。注意这里不是只选取 day 和 microsecond,而是从日期的 day 部分一直选取到 microsecond 部分。够强悍的吧!
MySQL Extract() 函数唯一不好的地方在于:你需要多敲几次键盘。
3. MySQL dayof... 函数:dayofweek(), dayofmonth(), dayofyear()
分别返回日期参数,在一周、一月、一年中的位置。
set @dt = '2008-08-08';

select dayofweek(@dt); -- 6
select dayofmonth(@dt); -- 8
select dayofyear(@dt); -- 221

日期 '2008-08-08' 是一周中的第 6 天(1 = Sunday, 2 = Monday, ..., 7 = Saturday);一月中的第 8 天;一年中的第 221 天。
4. MySQL week... 函数:week(), weekofyear(), dayofweek(), weekday(), yearweek()
set @dt = '2008-08-08';

select week(@dt); -- 31
select week(@dt,3); -- 32
select weekofyear(@dt); -- 32

select dayofweek(@dt); -- 6
select weekday(@dt); -- 4

select yearweek(@dt); -- 200831

MySQL week() 函数,可以有两个参数,具体可看手册。 weekofyear() 和 week() 一样,都是计算“某天”是位于一年中的第几周。 weekofyear(@dt) 等价于 week(@dt,3)。
MySQL weekday() 函数和 dayofweek() 类似,都是返回“某天”在一周中的位置。不同点在于参考的标准, weekday:(0 = Monday, 1 = Tuesday, ..., 6 = Sunday); dayofweek:(1 = Sunday, 2 = Monday, ..., 7 = Saturday)
MySQL yearweek() 函数,返回 year(2008) + week 位置(31)。
5. MySQL 返回星期和月份名称函数:dayname(), monthname()
set @dt = '2008-08-08';

select dayname(@dt); -- Friday
select monthname(@dt); -- August

思考,如何返回中文的名称呢?
6. MySQL last_day() 函数:返回月份中的最后一天。
select last_day('2008-02-01'); -- 2008-02-29
select last_day('2008-08-08'); -- 2008-08-31

MySQL last_day() 函数非常有用,比如我想得到当前月份中有多少天,可以这样来计算:
mysql> select now(), day(last_day(now())) as days;

+---------------------+------+
&#124; now() &#124; days &#124;
+---------------------+------+
&#124; 2008-08-09 11:45:45 &#124; 31 &#124;
+---------------------+------+

三、MySQL 日期时间计算函数
1. MySQL 为日期增加一个时间间隔:date_add()
set @dt = now();

select date_add(@dt, interval 1 day); -- add 1 day
select date_add(@dt, interval 1 hour); -- add 1 hour
select date_add(@dt, interval 1 minute); -- ...
select date_add(@dt, interval 1 second);
select date_add(@dt, interval 1 microsecond);
select date_add(@dt, interval 1 week);
select date_add(@dt, interval 1 month);
select date_add(@dt, interval 1 quarter);
select date_add(@dt, interval 1 year);

select date_add(@dt, interval -1 day); -- sub 1 day

MySQL adddate(), addtime()函数,可以用 date_add() 来替代。下面是 date_add() 实现 addtime() 功能示例:
mysql> set @dt = '2008-08-09 12:12:33';

mysql>
mysql> select date_add(@dt, interval '01:15:30' hour_second);

+------------------------------------------------+
&#124; date_add(@dt, interval '01:15:30' hour_second) &#124;
+------------------------------------------------+
&#124; 2008-08-09 13:28:03 &#124;
+------------------------------------------------+

mysql> select date_add(@dt, interval '1 01:15:30' day_second);

+-------------------------------------------------+
&#124; date_add(@dt, interval '1 01:15:30' day_second) &#124;
+-------------------------------------------------+
&#124; 2008-08-10 13:28:03 &#124;
+-------------------------------------------------+

date_add() 函数,分别为 @dt 增加了“1小时 15分 30秒” 和 “1天 1小时 15分 30秒”。建议:总是使用 date_add() 日期时间函数来替代 adddate(), addtime()。
2. MySQL 为日期减去一个时间间隔:date_sub()
mysql> select date_sub('1998-01-01 00:00:00', interval '1 1:1:1' day_second);

+----------------------------------------------------------------+
&#124; date_sub('1998-01-01 00:00:00', interval '1 1:1:1' day_second) &#124;
+----------------------------------------------------------------+
&#124; 1997-12-30 22:58:59 &#124;
+----------------------------------------------------------------+

MySQL date_sub() 日期时间函数 和 date_add() 用法一致,不再赘述。另外,MySQL 中还有两个函数 subdate(), subtime(),建议,用 date_sub() 来替代。
3. MySQL 另类日期函数:period_add(P,N), period_diff(P1,P2)
函数参数“P” 的格式为“YYYYMM” 或者 “YYMM”,第二个参数“N” 表示增加或减去 N month(月)。
MySQL period_add(P,N):日期加/减去N月。
mysql> select period_add(200808,2), period_add(20080808,-2)

+----------------------+-------------------------+
&#124; period_add(200808,2) &#124; period_add(20080808,-2) &#124;
+----------------------+-------------------------+
&#124; 200810 &#124; 20080806 &#124;
+----------------------+-------------------------+

MySQL period_diff(P1,P2):日期 P1-P2,返回 N 个月。
mysql> select period_diff(200808, 200801);

+-----------------------------+
&#124; period_diff(200808, 200801) &#124;
+-----------------------------+
&#124; 7 &#124;
+-----------------------------+

在 MySQL 中,这两个日期函数,一般情况下很少用到。
4. MySQL 日期、时间相减函数:datediff(date1,date2), timediff(time1,time2)
MySQL datediff(date1,date2):两个日期相减 date1 - date2,返回天数。
select datediff('2008-08-08', '2008-08-01'); -- 7
select datediff('2008-08-01', '2008-08-08'); -- -7

MySQL timediff(time1,time2):两个日期相减 time1 - time2,返回 time 差值。
select timediff('2008-08-08 08:08:08', '2008-08-08 00:00:00'); -- 08:08:08
select timediff('08:08:08', '00:00:00'); -- 08:08:08

注意:timediff(time1,time2) 函数的两个参数类型必须相同。

四、MySQL 日期转换函数、时间转换函数
1. MySQL (时间、秒)转换函数:time_to_sec(time), sec_to_time(seconds)
select time_to_sec('01:00:05'); -- 3605
select sec_to_time(3605); -- '01:00:05'

2. MySQL (日期、天数)转换函数:to_days(date), from_days(days)
select to_days('0000-00-00'); -- 0
select to_days('2008-08-08'); -- 733627

select from_days(0); -- '0000-00-00'
select from_days(733627); -- '2008-08-08'

3. MySQL Str to Date (字符串转换为日期)函数:str_to_date(str, format)
select str_to_date('08/09/2008', '%m/%d/%Y'); -- 2008-08-09
select str_to_date('08/09/08' , '%m/%d/%y'); -- 2008-08-09
select str_to_date('08.09.2008', '%m.%d.%Y'); -- 2008-08-09
select str_to_date('08:09:30', '%h:%i:%s'); -- 08:09:30
select str_to_date('08.09.2008 08:09:30', '%m.%d.%Y %h:%i:%s'); -- 2008-08-09 08:09:30

可以看到,str_to_date(str,format) 转换函数,可以把一些杂乱无章的字符串转换为日期格式。另外,它也可以转换为时间。“format” 可以参看 MySQL 手册。
4. MySQL Date/Time to Str(日期/时间转换为字符串)函数:date_format(date,format), time_format(time,format)
mysql> select date_format('2008-08-08 22:23:00', '%W %M %Y');

+------------------------------------------------+
&#124; date_format('2008-08-08 22:23:00', '%W %M %Y') &#124;
+------------------------------------------------+
&#124; Friday August 2008 &#124;
+------------------------------------------------+

mysql> select date_format('2008-08-08 22:23:01', '%Y%m%d%H%i%s');

+----------------------------------------------------+
&#124; date_format('2008-08-08 22:23:01', '%Y%m%d%H%i%s') &#124;
+----------------------------------------------------+
&#124; 20080808222301 &#124;
+----------------------------------------------------+

mysql> select time_format('22:23:01', '%H.%i.%s');

+-------------------------------------+
&#124; time_format('22:23:01', '%H.%i.%s') &#124;
+-------------------------------------+
&#124; 22.23.01 &#124;
+-------------------------------------+

MySQL 日期、时间转换函数:date_format(date,format), time_format(time,format) 能够把一个日期/时间转换成各种各样的字符串格式。它是 str_to_date(str,format) 函数的 一个逆转换。
5. MySQL 获得国家地区时间格式函数:get_format()
MySQL get_format() 语法:
get_format(date&#124;time&#124;datetime, 'eur'&#124;'usa'&#124;'jis'&#124;'iso'&#124;'internal'

MySQL get_format() 用法的全部示例:
select get_format(date,'usa') ; -- '%m.%d.%Y'
select get_format(date,'jis') ; -- '%Y-%m-%d'
select get_format(date,'iso') ; -- '%Y-%m-%d'
select get_format(date,'eur') ; -- '%d.%m.%Y'
select get_format(date,'internal') ; -- '%Y%m%d'
select get_format(datetime,'usa') ; -- '%Y-%m-%d %H.%i.%s'
select get_format(datetime,'jis') ; -- '%Y-%m-%d %H:%i:%s'
select get_format(datetime,'iso') ; -- '%Y-%m-%d %H:%i:%s'
select get_format(datetime,'eur') ; -- '%Y-%m-%d %H.%i.%s'
select get_format(datetime,'internal') ; -- '%Y%m%d%H%i%s'
select get_format(time,'usa') ; -- '%h:%i:%s %p'
select get_format(time,'jis') ; -- '%H:%i:%s'
select get_format(time,'iso') ; -- '%H:%i:%s'
select get_format(time,'eur') ; -- '%H.%i.%s'
select get_format(time,'internal') ; -- '%H%i%s'

MySQL get_format() 函数在实际中用到机会的比较少。
6. MySQL 拼凑日期、时间函数:makdedate(year,dayofyear), maketime(hour,minute,second)
select makedate(2001,31); -- '2001-01-31'
select makedate(2001,32); -- '2001-02-01'

select maketime(12,15,30); -- '12:15:30'

五、MySQL 时间戳(Timestamp)函数
1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()
mysql> select current_timestamp, current_timestamp();

+---------------------+---------------------+
&#124; current_timestamp &#124; current_timestamp() &#124;
+---------------------+---------------------+
&#124; 2008-08-09 23:22:24 &#124; 2008-08-09 23:22:24 &#124;
+---------------------+---------------------+

2. MySQL (Unix 时间戳、日期)转换函数:
unix_timestamp(),
unix_timestamp(date),
from_unixtime(unix_timestamp),
from_unixtime(unix_timestamp,format)

下面是示例:
select unix_timestamp(); -- 1218290027
select unix_timestamp('2008-08-08'); -- 1218124800
select unix_timestamp('2008-08-08 12:30:00'); -- 1218169800

select from_unixtime(1218290027); -- '2008-08-09 21:53:47'
select from_unixtime(1218124800); -- '2008-08-08 00:00:00'
select from_unixtime(1218169800); -- '2008-08-08 12:30:00'

select from_unixtime(1218169800, '%Y %D %M %h:%i:%s %x'); -- '2008 8th August 12:30:00 2008'

3. MySQL 时间戳(timestamp)转换、增、减函数:
timestamp(date) -- date to timestamp
timestamp(dt,time) -- dt + time
timestampadd(unit,interval,datetime_expr) --
timestampdiff(unit,datetime_expr1,datetime_expr2) --

请看示例部分:
select timestamp('2008-08-08'); -- 2008-08-08 00:00:00
select timestamp('2008-08-08 08:00:00', '01:01:01'); -- 2008-08-08 09:01:01
select timestamp('2008-08-08 08:00:00', '10 01:01:01'); -- 2008-08-18 09:01:01

select timestampadd(day, 1, '2008-08-08 08:00:00'); -- 2008-08-09 08:00:00
select date_add('2008-08-08 08:00:00', interval 1 day); -- 2008-08-09 08:00:00

MySQL timestampadd() 函数类似于 date_add()。
select timestampdiff(year,'2002-05-01','2001-01-01'); -- -1
select timestampdiff(day ,'2002-05-01','2001-01-01'); -- -485
select timestampdiff(hour,'2008-08-08 12:00:00','2008-08-08 00:00:00'); -- -12

select datediff('2008-08-08 12:00:00', '2008-08-01 00:00:00'); -- 7

MySQL timestampdiff() 函数就比 datediff() 功能强多了,datediff() 只能计算两个日期(date)之间相差的天数。

六、MySQL 时区(timezone)转换函数
convert_tz(dt,from_tz,to_tz)

select convert_tz('2008-08-08 12:00:00', '+08:00', '+00:00'); -- 2008-08-08 04:00:00

时区转换也可以通过 date_add, date_sub, timestampadd 来实现。
select date_add('2008-08-08 12:00:00', interval -8 hour); -- 2008-08-08 04:00:00
select date_sub('2008-08-08 12:00:00', interval 8 hour); -- 2008-08-08 04:00:00
select timestampadd(hour, -8, '2008-08-08 12:00:00'); -- 2008-08-08 04:00:00



MySql日期函数

Name   Description
ADDDATE()(v4.1.1)   Add time values (intervals) to a date value
ADDTIME()(v4.1.1)   Add time
CONVERT_TZ()(v4.1.3)   Convert from one timezone to another
CURDATE()   Return the current date
CURRENT_DATE(), CURRENT_DATE   Synonyms for CURDATE()
CURRENT_TIME(), CURRENT_TIME   Synonyms for CURTIME()
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP   Synonyms for NOW()
CURTIME()   Return the current time
DATE_ADD()   Add time values (intervals) to a date value
DATE_FORMAT()   Format date as specified
DATE_SUB()   Subtract two dates
DATE()(v4.1.1)   Extract the date part of a date or datetime expression
DATEDIFF()(v4.1.1)   Subtract two dates
DAY()(v4.1.1)   Synonym for DAYOFMONTH()
DAYNAME()(v4.1.21)   Return the name of the weekday
DAYOFMONTH()   Return the day of the month (0-31)
DAYOFWEEK()   Return the weekday index of the argument
DAYOFYEAR()   Return the day of the year (1-366)
EXTRACT   Extract part of a date
FROM_DAYS()   Convert a day number to a date
FROM_UNIXTIME()   Format UNIX timestamp as a date
GET_FORMAT()(v4.1.1)   Return a date format string
HOUR()   Extract the hour
LAST_DAY(v4.1.1)   Return the last day of the month for the argument
LOCALTIME(), LOCALTIME   Synonym for NOW()
LOCALTIMESTAMP, LOCALTIMESTAMP()(v4.0.6)   Synonym for NOW()
MAKEDATE()(v4.1.1)   Create a date from the year and day of year
MAKETIME(v4.1.1)   MAKETIME()
MICROSECOND()(v4.1.1)   Return the microseconds from argument
MINUTE()   Return the minute from the argument
MONTH()   Return the month from the date passed
MONTHNAME()(v4.1.21)   Return the name of the month
NOW()   Return the current date and time
PERIOD_ADD()   Add a period to a year-month
PERIOD_DIFF()   Return the number of months between periods
QUARTER()   Return the quarter from a date argument
SEC_TO_TIME()   Converts seconds to 'HH:MM:SS' format
SECOND()   Return the second (0-59)
STR_TO_DATE()(v4.1.1)   Convert a string to a date
SUBDATE()   A synonym for DATE_SUB() when invoked with three arguments
SUBTIME()(v4.1.1)   Subtract times
SYSDATE()   Return the time at which the function executes
TIME_FORMAT()   Format as time
TIME_TO_SEC()   Return the argument converted to seconds
TIME()(v4.1.1)   Extract the time portion of the expression passed
TIMEDIFF()(v4.1.1)   Subtract time
TIMESTAMP()(v4.1.1)   With a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments
TO_DAYS()   Return the date argument converted to days
UNIX_TIMESTAMP()   Return a UNIX timestamp
UTC_DATE()(v4.1.1)   Return the current UTC date
UTC_TIME()(v4.1.1)   Return the current UTC time
UTC_TIMESTAMP()(v4.1.1)   Return the current UTC date and time
WEEK()   Return the week number
WEEKDAY()   Return the weekday index
WEEKOFYEAR()(v4.1.1)   Return the calendar week of the date (0-53)
YEAR()   Return the year
YEARWEEK()   Return the year and week
背景:当使用对字符串验证的土图片破解后,有用snoopy去伪装请求,如下:破解完成上面的验证码,我们就可以使用snoopy(比curl要轻量,所以我喜欢)来模拟浏览器器,访问网站了。
来自:
http://blog.csdn.net/ugg/article/details/3953137  
http://blog.csdn.net/ugg/article/details/3972368

snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。  
下面是它的一些特征:  
1、方便抓取网页的内容  
2、方便抓取网页的文字(去掉HTML代码)  
3、方便抓取网页的链接  
4、支持代理主机  
5、支持基本的用户/密码认证模式  
6、支持自定义用户agent,referer,cookies和header内容  
7、支持浏览器转向,并能控制转向深度  
8、能把网页中的链接扩展成高质量的url(默认)  
9、方便提交数据并且获取返回值  
10、支持跟踪HTML框架(v0.92增加)  
11、支持再转向的时候传递cookies  
下面是简单的例子,比如说我们抓取我的blog的文字  

include "Snoopy.class.php";  
$snoopy = new Snoopy;  
$snoopy->fetchtext("http://www.phpobject.net/blog");  
echo $snoopy->results;

^_^,不错把,在比如抓取链接  

include "Snoopy.class.php";  
$snoopy = new Snoopy;  
$snoopy->fetchlinks("http://www.phpobject.net/blog");  
print_r($snoopy->results);

使用snoopy提交数据实现登陆  
模拟登陆可以用curl或者socket来实现,当curl需要服务器相应的启用curl module,自己socket实现相对比较麻烦,使用snoopy就简单了很多啦。  
在这里,我们使用喜悦国际村做为例子。(^_^,纯属研究)  
首先,我们要获取到登陆需要发送什么字段,目标地址是什么。这里我们使用snoopy的fetchform来实现。  
include "Snoopy.class.php";  
$snoopy = new Snoopy;  
$snoopy->fetchform("http://www.jackxiang.com/happy/logging.php?action=login");  
print $snoopy->results;  

当然你也可以直接查看http://www.jackxiang.com/happy/…的源代码来实现,不过这样更加方便把。这里,我们获取到目标和提交的数据,下一步就可以实现模拟登陆了。代码如下:  

include "Snoopy.class.php";  
$snoopy = new Snoopy;  
$submit_url = "http://www.jackxiang.com/happy/logging.php?action=login";  
    
$submit_vars["loginmode"] = "normal";  
$submit_vars["styleid"] = "1";  
$submit_vars["cookietime"] = "315360000";  
$submit_vars["loginfield"] = "username";  
$submit_vars["username"] = "********"; //你的用户名  
$submit_vars["password"] = "*******"; //你的密码  
$submit_vars["questionid"] = "0";  
$submit_vars["answer"] = "";  
$submit_vars["loginsubmit"] = "提   交";  
$snoopy->submit($submit_url,$submit_vars);  
print $snoopy->results;  
^_^,是不是显示你已经登陆了?使用snoopy就是这么简单!

参考使用php snoopy 类模拟GET/POST请求:http://outofmemory.cn/code-snippet/2463/usage-php-snoopy-class-moni-GET-POST-request

Download 类名:http://sourceforge.net/projects/snoopy/
代码参考:http://www.nowamagic.net/librarys/veda/detail/855
来源:http://blog.s135.com/tcsql/

 1、编译安装TCSQL需要的扩展库
wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
tar zxvf libevent-1.4.12-stable.tar.gz
cd libevent-1.4.12-stable/
./configure --prefix=/usr
make && make install
cd ../

wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz
tar zxvf json-c-0.9.tar.gz
cd json-c-0.9/
./configure --prefix=/usr/local/json-c-0.9
make && make install
cd ../

wget http://www.1978th.net/tokyocabinet/tokyocabinet-1.4.33.tar.gz
tar zxvf tokyocabinet-1.4.33.tar.gz
cd tokyocabinet-1.4.33/
./configure --prefix=/usr/local/tokyocabinet-1.4.33
make && make install
cd ../

echo "/usr/local/json-c-0.9/lib/" > /etc/ld.so.conf.d/json-c-0.9.conf
echo "/usr/local/tokyocabinet-1.4.33/lib/" > /etc/ld.so.conf.d/tokyocabinet-1.4.33.conf

/sbin/ldconfig


  2、编译TCSQL数据库
  注:二进制程序及源码目前只对金山公司内部开放。
gcc -o tcsql tcsql.c -levent -ljson -I/usr/local/json-c-0.9/include/json/ -L/usr/local/json-c-0.9/lib/ -ltokyocabinet -lz -lbz2 -lrt -lpthread -lm -lc -I/usr/local/tokyocabinet-1.4.33/include/ -L/usr/local/tokyocabinet-1.4.33/lib/

二、TCSQL数据库的启动
1、以自定义方式,作为守护进程启动:
ulimit -SHn 65535
./tcsql -l 192.168.8.34 -p 3888 -x /data0/tcsql/data -t 3 -d


  2、以默认值,作为守护进程启动:
ulimit -SHn 65535
./tcsql -d


  注:请确保文件描述符数量够用(系统默认值为1024),以便TCSQL承担上万连接数的并发访问。

很高兴能够看到这个时候mysql还能出个新版本,mysql 5.5.0是所谓的milestone version,这次带来了一些有趣的东西,按照重要程度(我主观上的)列一下:

◦支持Semisynchronous Replication,这个是从早期google的semi-sync patch转过来的,能够做到master-slave的半同步复制
◦集成Innodb plugin 1.0.6
◦新的partition语法
这个版本还不适合用在正式环境。想想以后也许可以用mysql mmm + mysql 5.5提供可用性更好的服务,前提是它已经足够稳定,或者是percona版本?
http://dev.mysql.com/downloads/mysql/5.5.html

官方不建议用于production环境


MySQL是现在最流行的开放源代码数据库.绝大多数PHP网站的数据库后台都是采用这一数据库.是一个多线程的,结构化查询语言(SQL)数据库服务器.MySQL 的执行性能非常高,运行速度非常快,并非常容易使用.是一个非常捧的数据库.

近日,关于Oracle收购Sun后MySQL将如何发展的问题可谓是热点新闻,很高兴能够看到这个时候mysql还能出个新版 本,而原来的 MySQL 5.4 在官网上已经没有链接,看来是升级为 5.5 版本了,官网上同时还提供一个从 5.4 升级到 5.5 的指南。MySQL 5.5.0是所谓的里程碑版本,这次带来了一些有趣的东西,按照重要程度(我主观上的)列一下:

* 支持半同步复制,这个是从早期google 的semi-sync patch转过来的,能够做到master-slave的半同步复制
* 集成Innodb plugin 1.0.6
* 支持 SQL 标准 SIGNAL 和 RESIGNAL 语句
* 增强XML功能,支持 LOAD XML 语句
* 可通过 ALTER TABLE … TRUNCATE PARTITION 来删除某个表在某个分区上的所有数据
* 增加了 TO_SECONDS 函数
* 新的 partition语法
* Key caches are now supported for indexes on partitioned MyISAM tables, using the CACHE INDEX and LOAD INDEX INTO CACHE statements

这个版本还不适合用在正式环境。想想以后也许可以用mysql mmm + mysql 5.5提供可用性更好的服务,前提是它已经足够稳定,或者是percona版本?

下载地址
5.5 版
http://dev.mysql.com/downloads/mysql/5.5.html

5.1 版
http://dev.mysql.com/downloads/mysql/5.1.html
PHP是目前网站开发中最受热捧的一款开源技术,最近发布了新版。该版本主要是提升了PHP5.3 的稳定性,修复了一些安全漏洞和bug。

  主要修改位置如下:

Added "max_file_uploads" INI directive, which can be set to limit the number of file uploads per-request to 20 by default, to prevent possible DOS via temporary file exhaustion.
Added missing sanity checks around exif processing.
Fixed a safe_mode bypass in tempnam().
Fixed a open_basedir bypass in posix_mkfifo().
Fixed failing safe_mode_include_dir.
  PHP团队建议所有PHP使用者升级至PHP 5.3.1。

  详细内容请看ChangeLog:http://www.php.net/ChangeLog-5.php#5.3.1

  下载地址:http://www.php.net/get/php-5.3.1.tar.gz/from/a/mirror
主要问题:

Fedora13 Alpha版本内核版本为:
2.6.33-0.52.rc8.git6.fc13.i686.PAE
其下载地址为:
ftp://rpmfind.net/linux/fedora/releases/test/13-Alpha/Fedora/i386/os/Packages/kernel-devel-2.6.33-0.52.rc8.git6.fc13.i686.rpm
注:不同的版本可在此网站找到相应的文件。
----- 如果网络畅通,可以 运行 [ yum -y install kernel-devel ],进行安装就6M,很快





参考网页:http://www.51ciw.com/debian_install/09_VMwareTools/VMwareTools.htm

为什么要装 VMware Tools?

因为它可以改善 Virtual Machine 的运行性能,而且可以让 Host OS 和 Guest OS 互通有无,这样我们就不用伤脑筋,要架设什么服务器,来沟通两个 OS,现在就让我们开始吧!

VMware Tools所在位置:VMware 安装路径 \VMware\VMware Workstation\linux.iso

[root@rd01 ~]# mount /cdrom    
# 有时可能加载不了,这时就要先将系统关闭,再手动指定 ISO 映像,看下图
[root@rd01 ~]# cd /cdrom
[root@rd01 ~]# ls -a
[root@rd01 ~]# cp VMwareTools-5.5.1-19175.tar.gz /tmp
[root@rd01 ~]# cd /tmp
[root@rd01 ~]# tar zxpf VMwareTools-5.5.1-19175.tar.gz
[root@rd01 ~]# cd vmware-tools-distrib
[root@rd01 vmware-tools-distrib]# ./vmware-install.pl
Creating a new installer database using the tar3 format.

Installing the content of the package.

# 安装过程的画面,全部使用默认值,一直按 Enter 就对了

In which directory do you want to install the binary files?
[/usr/bin]

What is the directory that contains the init directories (rc0.d/ to rc6.d/)?

[/etc/rc.d]

What is the directory that contains the init scripts?
[/etc/rc.d/init.d]

In which directory do you want to install the daemon files?
[/usr/sbin]

In which directory do you want to install the library files?
[/usr/lib/vmware-tools]

The path "/usr/lib/vmware-tools" does not exist currently. This program is goingto create it, including needed parent directories. Is this what you want?
[yes]

In which directory do you want to install the documentation files?
[/usr/share/doc/vmware-tools]

The path "/usr/share/doc/vmware-tools" does not exist currently. This program isgoing to create it, including needed parent directories. Is this what you want?
[yes]

The installation of VMware Tools 5.5.1 build-19175 for Linux completed
successfully. You can decide to remove this software from your system at any
time by invoking the following command: "/usr/bin/vmware-uninstall-tools.pl".

Before running VMware Tools for the first time, you need to configure it by
invoking the following command: "/usr/bin/vmware-config-tools.pl". Do you want
this program to invoke the command for you now? [yes]


Stopping VMware Tools services in the virtual machine:
  Guest operating system daemon:                          [  确定  ]
Trying to find a suitable vmhgfs module for your running kernel.

The module bld-2.6.9-5.EL-i686-RHEL4 loads perfectly in the running kernel.

pcnet32                30153  0
Unloading pcnet32 module

Trying to find a suitable vmxnet module for your running kernel.

The module bld-2.6.9-5.EL-i686-RHEL4 loads perfectly in the running kernel.



Detected X.org version 6.8.

关闭控制台鼠标服务:                                       [  确定  ]
启动控制台鼠标服务:                                       [  确定  ]

Please choose one of the following display sizes (1 - 13):

# 显示分辨率,这里是以 1024x768 为例

# VMware Tools 安装的时候,会自动修改 X server 的配置文件

[1]  "640x480"
[2]< "800x600"
[3]  "1024x768"
[4]  "1152x864"
[5]  "1280x800"
[6]  "1152x900"
[7]  "1280x1024"
[8]  "1376x1032"
[9]  "1400x1050"
[10]  "1680x1050"
[11]  "1600x1200"
[12]  "1920x1200"
[13]  "2364x1773"
Please enter a number between 1 and 13:

[2] 3


X Window System Version 6.8.2
Release Date: 9 February 2005
X Protocol Version 11, Revision 0, Release 6.8.2
Build Operating System: Linux 2.6.9-34.EL i686 [ELF]
Current Operating System: Linux rd01.domain 2.6.9-34.EL #1 Wed Mar 8 00:07:35 CST 2006 i686
Build Date: 04 May 2006
Build Host: x8664-build.centos.org

       Before reporting problems, check http://wiki.X.Org
       to make sure that you have the latest version.
Module Loader present
OS Kernel: Linux version 2.6.9-34.EL (buildcentos@build-i386) (gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)) #1 Wed Mar 8 00:07:35 CST 2006 P
Markers: (--) probed, (**) from config file, (==) default setting,
       (++) from command line, (!!) notice, (II) informational,
       (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(++) Log file: "/tmp/vmware-config0/XF86ConfigLog.3131", Time: Mon Jun 12 20:57:34 2006
(++) Using config file: "/tmp/vmware-config0/XF86Config.3131"
(WW) VMWARE(0): Failed to set up write-combining range (0xf0000000,0x1000000)

X is running fine with the new config file.

Starting VMware Tools services in the virtual machine:
  Switching to guest configuration:                       [  确定  ]
  Guest filesystem driver:                                [  确定  ]
  DMA setup:                                              [  确定 ]
  Guest operating system daemon:                          [  确定  ]

The configuration of VMware Tools 5.5.1 build-19175 for Linux for this running
kernel completed successfully.

You must restart your X session before any mouse or graphics changes take
effect.

You can now run VMware Tools by invoking the following command:
"/usr/bin/vmware-toolbox" during an XFree86 session.

To use the vmxnet driver, restart networking using the following commands:
/etc/init.d/network stop
rmmod pcnet32
rmmod vmxnet
depmod -a
modprobe vmxnet
/etc/init.d/network start

Enjoy,

--the VMware team

[root@rd01 vmware-tools-distrib]# shutdown -r now

# 修改完成之后,重新启动计算机,让 VMware Tools 生效



# 重新启动计算机之后,我们就会发觉到,当我们要离开 Guest OS 的时候,不再需要按 Ctrl + Alt 了,

# 现在我们来共享 Host OS 的文件夹给 Guest 使用,〔VM〕→〔设置 Ctrl + D〕

# 注:左下角原本都会显示「You do not have VMware Tools installed」,现在我们装了 VMware Tools,就不再显示了













# 这就是共享完毕的画面,然后我们就需要到 Guest OS 内,看看可不可以读取到刚刚共享的目录

# 顺利的话,我们只要到「/mnt/hgfs」文件夹,就可以看到刚刚共享的文件夹了
分页: 190/272 第一页 上页 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 下页 最后页 [ 显示模式: 摘要 | 列表 ]