Ôoôʹ Mysql Êý¾Ýͬ²½ ÏȼÙÉeÓÐÖ÷»u A ºÍ B ( Linux ϵͳ)£¬Ö÷»u A µÄ IP *Ö±ðÊÇ 1.2.3.4 (µ±È»£¬Ò²¿ÉÒÔÊǶ¯Ì¬µÄ)£¬Ö÷»u B µÄ IP ÊÇ 5.6.7.8 ¡£Á½¸oÖ÷»u¶¼×°ÉÏÁË PHP+Mysql £¬ÏÖÔÚ²Ù×÷µÄÊÇÖ÷»u A ÉϵÄ×ÊÁÏ£¬Èç¹uÁiÍaÒ»¸oÖ÷»u B Ïe¸u A µÄ×ÊÁϽøÐÐͬ²½£¬Ó¦¸ÃÔoô×oÄØ£¿
OK£¬ÎÒÃÇÏÖÔھͶ¯ÊÖ¡£
Ê×ÏÈ£¬Èç¹uÒªÏeÁ½¸oÖ÷»u¼aµÄ×ÊÁÏͬ²½£¬Ò»ÖÖ½¨¾ÍÊÇÖ÷»u A ÍuÖ÷»u B ËÍ×ÊÁÏ£¬ÁiÍaÒ»ÖÖÖ÷*¨¾ÍÊÇÖ÷»u B µ½Ö÷»u A ÉÏÄÃ×ÊÁÏ£¬ÒoΪ A µÄ IP ÊǶ¯Ì¬µÄ(¼ÙÉe)£¬ËuÒÔÎÒÃǾ͵ôÓÖ÷»u A ÍuÖ÷»u B ËÍ×ÊÁÏ¡£
ÔÚÖ÷»u B ÉÏ´´½¨Ò»¸o Mysql ÕË»§¡£
Èç¹uÕaÀiÏÔʾ´iÎo£¬ÏÈ°Ñ % ¸ÄΪһ¸o IP £¬È»ºoÔÙÀuÓà phpMyAdmin °Ñ IP ¸ÄΪ % £¬²aÊÔÎÞÎoºo¾Í¿ÉÒÔд php ³ÌÐo¡£
<?
$link=mysql_pconnect("localhost","user","password");
mysql_pconnect("localhost","user","password"); //Á¬½Ó±¾»u(Ö÷»uA)µÄÊý¾Ý¿a
mysql_select_db("test"); //Ñ¡ÔñÊý¾Ý¿atest
$re=mysql_query("select * from table order by id desc");
$num=mysql_numrows($re);
if (!empty($num)) {
$id=mysql_result($re,0,"id"); //»ñµÃ±¾»utable±iµÄ×i´oID
}
mysql_close($link); //¹Ø±ÕÓe±¾»uÊý¾Ý¿aµÄÁ¬½Ó
$link=mysql_pconnect("5.6.7.8","test","test");
mysql_pconnect("5.6.7.8","test","test"); //Á¬½ÓÖ÷»uBµÄÊý¾Ý¿a
mysql_select_db("test"); //Ñ¡ÔñÊý¾Ý¿atest£¬´ËÊý¾Ý¿aÓ¦¸ÃÓeÖ÷»uAÉÏtestÊý¾Ý¿aµÄ½a¹¹Ò»Ñu¡£
$re=mysql_query("select * from table order by id desc");
$num=mysql_numrows($re);
if (!empty($num)) {
$remote_id=mysql_result($re,0,"id"); //»ñµÃÖ÷»uBtable±iµÄ×i´oID
}
if ($id>$remote_id) {
$result_id=$id-$remote_id; //Èç¹uÖ÷»uAÖÐtableµÄ×i´oID´oÓÚÖ÷»uBÖÐtable±iµÄ×i´oID£¬ËµÃ÷Á½¸o
} µÄ×ÊÁϲ»Í¬
mysql_close($link); //¹Ø±ÕÖ÷»uBµÄÊý¾Ý¿aÁ¬½Ó
$link=mysql_pconnect("localhost","user","password");
mysql_pconnect("localhost","user","password");
mysql_select_db("test");
if (empty($result_id)) $result_id=0;
if (empty($remote_id)) $remote_id=0; //Èç¹uÖ÷»uBÖеÄtableµÄ×i´oIDΪ¿Õ(ÀiÃaeûÓÐ×ÊÁÏ),ÄÇô¾ÍµÈ0
$re=mysql_query("select from table limit $remote_id,$result_id"); //È¡³oÖ÷»uAÖÐtable±iÓeÖ÷»uBÖÐtable±iÀi²»Í¬µÄ×ÊÁÏ
$num=mysql_numrows($re);
if (!empty($num)) {
for ($i=0;$i<$num;$i++) {
$test[$i]=mysql_result($re,$i,"test"); //°Ñ²»Í¬µÄ×ÊÁÏÅÈeÒ»¸oÊý×eÀi
}
}
mysql_close($link); //¹Ø±ÕÖ÷»uAµÄÊý¾Ý¿aÁ¬½Ó
$link=mysql_pconnect("5.6.7.8","user","password");
mysql_pconnect("5.6.7.8","user","pasword");
mysql_select_db("test");
for ($j=0;$j<$i;$j++) { //ÕaÀiµÄiµÈÓÚÔڱȽÏÖ÷»uAÓeÖ÷»uBÉÏtable±i²»Í¬×ÊÁϵÄÊýÁ¿
mysql_query("insert into table (test) values(\'$test[$j]\')");
}
mysql_close($link); //¹Ø±ÕÖ÷»uBµÄÊý¾Ý¿aÁ¬½Ó
?>
Õaʱ¾Í³o²½ÊµÏÖÁË A Ö÷»uºÍ B Ö÷»uÊý¾ÝµÄͬ²½£¬µ«ÏÖÔÚ»¹ÐeÒªÈËÊÖ¶¯Ã¿´ÎÈ¥¼¤»iÕa¸o³ÌÐo£¬ÓÐûÓаi¨°ÑËu×÷Ϊһ¸o½Å±¾Ò»ÑuµÄ£¬ÅÔÚ crontab ÀiÃaeÖ¸¶¨Ê±¼a×Ô¶¯Ö´ÐÐÄØ£¿
ÔÚ°²×° php ʱ»a×Ô¶¯ÉuÒ»¸o½Ð php µÄ¿ÉÖ´ÐÐÎļþ£¬Ò»°aÔÚ/Äa°²×°µÄ php Ŀ¼ /bin ÏÂÃae£¬²»¹ý½Ïµ×µÄ°ae±¾ºÃÏñûÓУ¬Èç¹uûÓÐÕa¸oÎļþ£¬Äa¾ÍµÃÉý¼¶ÄaµÄ php ¡£
php Ô±¾ÊÇÓ¦ÓÃÔÚÍøÒ³Ó¦ÓõÄ(C)oÒo´ËËu»aËͳo HTML µÄ Header(C)oµ«ÊÇÔÚ´ËÎÒÃÇÊÇÒª½« php ÓÃ×÷ Shell Script(C)o"-q" ¾ÍÊDZiʾ²»ÒªËͳo Header µÄÒa˼.
×iºo±a¼ /etc/crontab ÀiµÄÎļþ£¬¼ÓÉÏÏÂÃaeÕaÒ»¾a¡£
0 0 root /home/httpd/html/test //ÿÌiÍiÉÏÁaµaÖ´/home/httpd/html/testÎļþ(¾ßÌaʹÓý*¨Çe²e¿´cronµÄÏa¹Ø×ÊÁÏ)
OK£¬µ½ÕaÀi²i²»¶a¾ÍÒÑÍe³É Mysql Êý¾ÝµÄͬ²½ÁË£¬Èç¹u¸÷λ»¹ÓÐÐËȤµÄ»°£¬¿ÉÒÔÏeÒ»¸oÁ¬±a¼¡¢É¾³ý¶¼ÄÜͬ²½µÄ¸uºÃµÄ°i*¨¡£