PHP(MySQL) ¿ø°ÝÁö¼­¹ö Table À» ·ÎÄà Table ·Î ¹é¾÷ º¹»ç
Á¶È¸ : 340 À̸§ : ºÒ¹Ù´Ù
E-mail :
¿ø°ÝÁö ¼­¹ö MYSQL µ¥ÀÌŸº£À̽º¸¦ Å×ÀÌºí ´ÜÀ§·Î ·ÎÄà µ¥ÀÌŸº£À̽º ¼­¹ö·Î ¹é¾÷°ú º¹»ç¸¦ ÇØÁÖ´Â PHP ½ºÅ©¸³Æ® ¼Ò½º ÄÚµåÀÔ´Ï´Ù. Å×À̺í¸íÀÌ "tc_"·Î ½ÃÀÛÇÏ´Â Å×ÀÌºí¸¸ º¹»çÇϵµ·Ï Á¶°Ç¹®ÀÌ ºÙ¾î ÀÖ½À´Ï´Ù. ºÒÇÊ¿äÇϸé "tc_" ¸¦ ""·Î ¼öÁ¤ÇϽðųª ÇØ´ç ÁÙÀ» ÁÖ¼®Ã³¸®ÇÏ¸é µÇ°í mysql °ú mysqldump ÀÇ °æ·Î°¡ ´Ù¸¦ ¼ö ÀÖÀ¸¹Ç·Î È®ÀÎÇÏ°í ´Ù¸£¸é ¼öÁ¤ÇؾßÇÕ´Ï´Ù.
¾Æ·¡ ¼Ò½º Äڵ带 ½ÇÇàÇÒ ¶§, ·ÎÄà ¼­¹ö ÃֽŠµ¥ÀÌŸ¸¦ µ¤¾î¹ö¸± ¼ö ÀÖÀ¸¹Ç·Î ÁÖÀDZí°Ô ´Ù·ç¾î¾ß ÇÕ´Ï´Ù.
$check_prefix = "tc_";

$db_info['host'] = "192.168.0.10";
$db_info['db'] = "blog";
$db_info['user'] = "root";
$db_info['password'] = "password";

$db_info['date'] = date("Ymd");
if (!file_exists($db_info['date'])) mkdir($db_info['date'],0700);
$db_info['session'] = mysql_connect($db_info['host'], $db_info['user'], $db_info['password']) or die("SQL¼­¹ö¿¡ Á¢¼ÓÇÒ ¼ö ¾ø½À´Ï´Ù.");

$query = "show databases";
$out1 = mysql_query($query);
if ($out1)
while ($row1 = mysql_fetch_row($out1)) {
echo $row1[0];
$db_info['db'] = $row1[0];
$db_info['outdir'] = $db_info['date'] . "/" . $row1[0];
if (!file_exists($db_info['outdir'])) mkdir($db_info['outdir'],0700);
$query = "show tables";
if (mysql_select_db($row1[0])) {
echo " +\n";
$out2 = mysql_query($query);
if ($out2)
while ($row2 = mysql_fetch_row($out2)) {
$db_info['table'] = $row2[0];
if (strlen($check_prefix)){
if (substr($db_info['table'],0,strlen($check_prefix))!=$check_prefix) continue;
}
$db_info['outfile'] = $row2[0] . ".sql";
$db_info['outpath'] = $db_info['outdir'] . "/" . $db_info['outfile'];
echo "\t".$row2[0]."\n";

$str = "/usr/bin/mysqldump -h".$db_info['host']." -u".$db_info['user']." -p".$db_info['password']." ".$db_info['db']." ".$db_info['table']." > ".$db_info['outpath'];
passthru($str);
$str = "/usr/bin/mysql -hlocalhost -u".$db_info['user']." -p".$db_info['password']." ".$db_info['db']." < ".$db_info['outpath'];
passthru($str);
}
} else {
echo " -\n";
}
}
?>

À¥ÇÁ·Î±×·¡¸ÓÀÇ È¨ÆäÀÌÁöÁ¤º¸ ºí·Î±× http://hompy.info
ÀÛ¼º ³¯Â¥ : 2008-01-17