µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux×ÛºÏ - ¹ØÓÚÈçºÎ±¸·ÝÊý¾Ý¿â(Mysql)µÄ¼òÒ׳ÌÐò

¹ØÓÚÈçºÎ±¸·ÝÊý¾Ý¿â(Mysql)µÄ¼òÒ׳ÌÐò

¡¡¡¡ÔÚ¹«Ë¾£¨ÍøÂ磩µÄ·þÎñÆ÷ÉÏÓкܶàÍøÕ¾£¬ÎÒÉÏ´«Íøվʱ¶ÔÆäËûÍ߸ÉÒ²ÓÐͬÑùµÄȨÏÞ¡£ËùÒÔ¾ÍÏë°ÑͬʵÄÍøÕ¾µ´ÏÂÀ´Ñ§Ï°Ò»Ï¡£ÓÐÁËÔ´´úÂ룬ûÓÐÊý¾Ý¿âʲôҲÔËÐв»ÁË°¡¡£·þÎñÆ÷µÄÊý¾Ý¿âÊÇ°²ÍøÕ¾¿ªµÄ£¬Ã¿Ò»¸öÍøÕ¾°Ñ*.sql·¢¸ø·þÎñÆ÷¹ÜÀíÔ±£¬ÓɹÜÀíÔ±µ¼Èëµ½Êý¾Ý¿âÖС£µ«ÊÇÊý¾Ý¿âÕ˺ÅÃÜÂë²»ÄܵǽֻÄÜÖ´ÐÐsqlÓï¾ä¡£ËùÒÔÎÒ¾ÍÏëÆðÀ´×öÒ»¸ö¼òÒ׵ģ¬ÀàËÆÓÚPHPmyadminµÄÊý¾Ý¿âµ¼³ö¹¦ÄÜ¡£ÕâÑùÎҾͿÉÒÔÇáËɵĻñµÃËùÓÐÍøÕ¾µÄÊý¾Ý¿âÁË¡£¡¡¡¡¡¡¡¡ÓÃÕâ¸ö³ÌÐò¿ÉÒÔʵÏÖ¼òµ¥µÄÊý¾Ýµ¼³ö£¨Éú³ÉµÄ½Å±¾¿ÉÖ±½ÓÔÚphpmyadminÖ´ÐУ©¡£½øÒ»²½µÄ¹¦ÄÜ»¹¿ÉÒÔÂýÂýÀ©Õ¹¡£µ±È»²»ÒªÓÃÀ´µÁÓñðÈË»úÃܵĶ¬¶¬ÁË¡£¡¡¡¡¡¡¡¡ÆäÖнâÎöµÄÊý¾ÝÀàÐÍ»¹²»È«,Ö»ÊǼ¯Öмòµ¥µÄ³£ÓÃÀàÐÍ¡£Èç¹ûÄÇλÈÊÐÖ£¬·¢ÏÖÁËÆäËû²»ÊÊÓõÄÀàÐÍ£¬Çë¸æËßÎÒmailto:[email protected]¡£¡¡¡¡ ¡¡¡¡index.php¡¡¡¡¡¡¡¡<Html>¡¡¡¡<head>¡¡¡¡<meta http-equiv="Content-Type" content="text/html; charset=gb2312">¡¡¡¡<title>Êý¾Ý¿â±¸·Ý</title>¡¡¡¡<style type="text/Css">¡¡¡¡.borderoff{ border-style:none; background-color:#F3F3F3}¡¡¡¡</style>¡¡¡¡</head>¡¡¡¡<body>¡¡¡¡<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center">¡¡¡¡<tr valign="top">¡¡¡¡<td height="378"><br>¡¡¡¡<form action="cmd.php" method="post" name="backup" target="_blank" id="backup">¡¡¡¡<table width="500" border="0" cellspacing="1" cellpadding="4" align="center">¡¡¡¡<tr>¡¡¡¡<td colspan="2" align="center">Êý¾Ý¿â±¸·Ý</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right"> ·þÎñÆ÷Ãû£º</td>¡¡¡¡<td width="313"><input name="hostname" type="text" class="borderoff" value="localhost" size="35" maxlength="50">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right"> Êý¾Ý¿âÃû£º</td>¡¡¡¡<td width="313"><input name="database" type="text" class="borderoff" value="yes_da" size="35" maxlength="50">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right">ÕË    ºÅ£º</td>¡¡¡¡<td width="313"><input name="username" type="text" class="borderoff" value="root" size="35" maxlength="50">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right">ÃÜ    Â룺</td>¡¡¡¡<td width="313"><input name="passWord" type="text" class="borderoff" size="35" maxlength="50">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right"> ÍêÈ«±¸·Ý£º</td>¡¡¡¡<td width="313">¡¡¡¡<input type="radio" name="backup_type" value="full" checked>¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right">Ö»±¸·Ý½á¹¹£º</td>¡¡¡¡<td width="313">¡¡¡¡<input type="radio" name="backup_type" value="strUCture">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right">Ö»±¸·ÝÊý¾Ý£º</td>¡¡¡¡<td width="313">¡¡¡¡<input type="radio" name="backup_type" value="data">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡<tr bgcolor="#F3F3F3">¡¡¡¡<td width="166" align="right">²ÉÓÃѹËõ¸ñʽ£º</td>¡¡¡¡<td width="313">¡¡¡¡<input type="radio" name="gzipcompress" value="0" checked>¡¡¡¡·ñ¡¡¡¡<input type="radio" name="gzipcompress" value="1">¡¡¡¡ÊÇ(zip)</td>¡¡¡¡</tr>¡¡¡¡<tr>¡¡¡¡<td colspan="2" align="center">¡¡¡¡<input name="backupstart" type="submit" value="¿ªÊ¼±¸·Ý">¡¡¡¡</td>¡¡¡¡</tr>¡¡¡¡</table>¡¡¡¡</form>¡¡¡¡<p align="center"> <br>¡¡¡¡<br>¡¡¡¡</p></td>¡¡¡¡</tr>¡¡¡¡</table>¡¡¡¡</body>¡¡¡¡</html>¡¡¡¡¡¡¡¡cmd.php¡¡¡¡¡¡¡¡<?php¡¡¡¡if(isset($_POST['backupstart']))¡¡¡¡{¡¡¡¡$hostname = trim($_POST['hostname']);¡¡¡¡$database = trim($_POST['database']);¡¡¡¡$username = trim($_POST['username']);¡¡¡¡$password = trim($_POST['password']);¡¡¡¡$backtype = $_POST['backup_type'];¡¡¡¡$gz¡¡ = $_POST['gzipcompress'];¡¡¡¡¡¡¡¡$link = @mysql_pconnect($hostname, $username, $password);¡¡¡¡if(!$link)¡¡¡¡{¡¡¡¡//Á¬½ÓÊý¾Ý¿â¡¡¡¡echo "Êý¾Ý¿â´ò¿ª³ö´í£¡";¡¡¡¡exit();¡¡¡¡}//end if¡¡¡¡¡¡¡¡$table_list = get_table_list($link,$database);¡¡¡¡if($table_name===false)¡¡¡¡{¡¡¡¡//¼ìË÷Êý¾Ý¿âµÄ±í¡¡¡¡echo "Êý¾Ý¿â´ò¿ª³ö´í£¡£¡";¡¡¡¡exit();¡¡¡¡}//end if¡¡¡¡//echo "<pre>";¡¡¡¡//print_r($table_list);¡¡¡¡¡¡¡¡$table_code = "";¡¡¡¡while(list($key,$table_name)=each($table_list))¡¡¡¡{¡¡¡¡//Ö´ÐжÔÿһ¸ö±íµÄÊý¾Ý·µ»Ø¡¡¡¡if($backtype!="data")¡¡¡¡{¡¡ //±¸·Ý½á¹¹¡¡¡¡$table_code .= get_table_code($link,$database,$table_name);¡¡¡¡}//end if¡¡¡¡if($backtype!="structure")¡¡¡¡{¡¡ //±¸·ÝÊý¾Ý¡¡¡¡$table_code .= get_table_data($link,$database,$table_name);¡¡¡¡}//end if¡¡¡¡}//end while¡¡¡¡//echo $table_code;¡¡¡¡if($gz==0)¡¡¡¡{¡¡¡¡//Êä³ö¡¡¡¡$filename = $database.".sql";¡¡¡¡$handle = fopen($filename, "a+");¡¡¡¡$temp = fwrite($handle, $table_code);¡¡¡¡echo $temp;¡¡¡¡fclose($handle);¡¡¡¡//header("location:",$filename);¡¡¡¡¡¡¡¡echo "<script>location.replace('".$filename."');</script>";¡¡¡¡¡¡¡¡}elseif($gz==1){¡¡¡¡$filename = $database.".zip";¡¡¡¡$fp = gzopen($filename, "w9");¡¡¡¡gzwrite($fp,$table_code);¡¡¡¡gzclose($fp);¡¡¡¡¡¡¡¡//header("location:",$filename);¡¡¡¡¡¡¡¡echo "<script>location.replace('".$filename."');</script>";¡¡¡¡¡¡¡¡}//end if¡¡¡¡¡¡¡¡}else{¡¡¡¡echo "Á¬½Ó´íÎ󣡣¡£¡";¡¡¡¡exit();¡¡¡¡}//end if¡¡¡¡//*****************************************************************¡¡¡¡//º¯ÊýÃû£ºget_table_list¡¡¡¡//¹¦ÄÜ£º·µ»ØÖ¸¶¨Êý¾Ý¿âÖеÄËùÓбíÃû¡¡¡¡//²ÎÊý£º$link¡¡ÊÇÊý¾Ý¿âÁ¬½Ó¡¡¡¡//¡¡$database¡¡Êý¾Ý¿âÃû¡¡¡¡//ʱ¼ä£º2004Äê3ÔÂ23ÈÕ¡¡¡¡//×÷ÕߣºÒ°Âí¡¡¡¡//QQ£º£´£¶£±£¶£³£°£²£°¡¡¡¡//Email£º[email protected]¡¡¡¡//*****************************************************************¡¡¡¡function get_table_list($link,$database)¡¡¡¡{¡¡¡¡$result = @mysql_list_tables($database);¡¡¡¡if(!$result)¡¡¡¡{//Åжϴò¿ªÊÇ·ñ³ö´í¡¡¡¡return false;¡¡¡¡}//end if¡¡¡¡while($row = mysql_fetch_row($result))¡¡¡¡{¡¡¡¡$table_name[] = $row[0];¡¡¡¡}//end while¡¡¡¡mysql_free_result($result);¡¡¡¡return $table_name;¡¡¡¡}//end function¡¡¡¡//*****************************************************************¡¡¡¡//º¯ÊýÃû£ºget_table_code¡¡¡¡//¹¦ÄÜ£º·µ»ØÖ¸¶¨Êý¾Ý¿âÖбíµÄ½á¹¹£¬ÓÃÓÚ´´½¨Ö¸¶¨±íµÄSQLÓï¾ä¡¡¡¡//²ÎÊý£º$link¡¡ÊÇÊý¾Ý¿âÁ¬½Ó¡¡¡¡//¡¡$database¡¡Êý¾Ý¿âÃû¡¡¡¡//¡¡$table_name±íÃû¡¡¡¡//ʱ¼ä£º2004Äê3ÔÂ23ÈÕ¡¡¡¡//×÷ÕߣºÒ°Âí¡¡¡¡//QQ£º£´£¶£±£¶£³£°£²£°¡¡¡¡//Email£º[email protected]¡¡¡¡//*****************************************************************¡¡¡¡function get_table_code($link,$database,$table_name)¡¡¡¡{¡¡¡¡mysql_select_db($database, $link);¡¡¡¡$result = mysql_query("select * from ".$table_name, $link);¡¡¡¡$return_str = "CREATE TABLE `".$table_name."` (\n\t";¡¡¡¡$fields_num = (int)mysql_num_fields($result);¡¡¡¡¡¡¡¡$fun_my['string'] = "varchar";¡¡¡¡$fun_my['datetime'] = "datetime";¡¡¡¡$fun_my['blob'] = "text";¡¡¡¡$fun_my['real'] = "float";¡¡¡¡echo "<br>";¡¡¡¡for($i=0; $i < $fields_num; $i++)¡¡¡¡{¡¡¡¡$return_str .= "`".mysql_field_name($result, $i)."` ";¡¡¡¡¡¡¡¡$type = mysql_field_type($result, $i);¡¡¡¡if(isset($fun_my[$type]))¡¡¡¡{¡¡¡¡//½âÎöÊý¾ÝÀàÐÍ¡¡¡¡if($fun_my[$type]=="datetime" $fun_my[$type]=="text")¡¡¡¡{¡¡¡¡$return_str .= $fun_my[$type]." ";¡¡¡¡}else{¡¡¡¡$return_str .= $fun_my[$type]."(".mysql_field_len($result, $i).") ";¡¡¡¡}//end if¡¡¡¡}else{¡¡¡¡$return_str .= $type."(".mys
[1] [2] ÏÂÒ»Ò³ 

£¨³ö´¦£ºhttp://www.sheup.com£©


ÉÏÒ»Ò³ [1] [2]