Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24
export – unethost無限空間虛擬主機 技術分享部落格

mysql export import

如果要備分或是還原資料庫,遇到資料庫超過一定的大小,例如20MB之後,許多php版本的自動匯出/匯入程式都會出問題。因為php程式會受到 max_upload_size, max_execution_time等參數的限制。甚至連phpmyadmin也會有不管用的時候。

遇到這種時候,如果追求速度(不計難度),最有效率的方法,自然是透過ssh登入,直接下mysqldump指令來解決問題。

匯出: mysqldump -u 使用者名稱 -p –opt  -h localhost  資料庫名稱 > 檔案名.sql
匯入: mysql -u 使用者名稱 -p 資料庫名稱 < 檔案名.sql

然而,上述的方法,牽扯到使用ssh。這對很多只會用ftp的使用者是一大門檻。當然,也是有不需要ssh的解法。
(*) 匯出   backup your mysql database using php 

程式在這邊,使用方法:
(1) 修改這一行
backup_tables(‘localhost’,”使用者名”,”密碼”,”資料庫名”);
(2) 透過網頁來啟動這個php檔。
(3) 執行完後,這個php檔會自動生成一個mysql database的匯出檔。再用ftp下載即可。

這個程式看起來還滿複雜的,有些人心裡應該會有疑惑,明明php也可以直接呼叫 linux的指令吧? php可以做這件事,但是,在虛擬主機的環境中,為了安全性,這個直接呼叫 linux指令功能一向是被關閉的。所以才需要寫得這麼麻煩。

(*) 匯入  BigDump

使用方法如下:
(1) 在bigdump的官網上,下載bigdump.php這個檔案的壓縮檔。並且解壓縮。
(2) 修改bigdump.php的內容

$db_server = '主機名稱';(一般為localhost)
$db_name = '資料庫名稱';
$db_username = '使用者帳號';
>$db_password = '使用者密碼'

(3)  修改bigdump.php的內容

$filename = '檔案名稱.sql';
$ajax = true;
$linespersession = 3000; (設定每次還原幾筆資料)
$delaypersession = 5000; (每次間隔休息時間,設定5000為休息5秒鐘。)

(4) 將「bigdump.php」與「檔案名稱.sql」放入同一個資料夾,並上傳至伺服器。
最後打開瀏覽器輸入bigdump.php 所在網址,如: http://domain.tw/dump/bigdump.php

(5)當藍bar全滿後,出現「Congratulations: End of file reached, assuming OK」的訊息後,表示資料庫匯入完成。