我需要知道如何使用cron作業每6小時刪除或刪除一個數據庫,並使用演示.sql創建它。 在我的cPanel我創建的cron是這樣的:使用cron作業刪除數據庫
0 0 1 * * /home/escyv/restore_data.sh
和cron的執行命令,但是當cron作業執行命令不作出任何下降Ø截斷。
這裏的腳本:
restore_data.sh
#! /bin/sh
clear;
#fill in your database information here
user="escyv_cyv";
password="ky21m1";
server="localhost";
database_name="escyv_cyv";
#path to the backup database file
restore_file="0db0/escyv_db.sql";
#here the script deletes all your tables in the database
mysql --user=$user --password=$password -h $server -BNe "SHOW TABLES" $database_name | tr '\n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " $1 ";SET
FOREIGN_KEY_CHECKS = 1;"}' | mysql --user=$user --password=$password -h $server $database_name;
echo "Base de datos limpiandose!";
echo "Restaurando Base de Datos..";
#here the script restores the database
mysql --user=$user --password=$password host=$server $database_name < $restore_file;
echo "Base de datos restaurada!";
我測試它改變它的恢復文件escyv_db.sql的名稱escyv_db1.sql,看看該網站顯示錯誤,但告訴我在數據庫中的全部信息......所以我認爲該命令沒有作出什麼..
對不起我的英文不好......是不是我的母語
最佳雷加DS!
安德烈斯
----- -----編輯本 腳本工作!感謝@itsols
這是新restore_data.sh
#! /bin/sh
clear;
#here the script deletes all your tables in the database
mysql -u escyv -pky21m1 -e 'drop database escyv_cyv;'
echo "Base de datos limpiandose!";
mysql -u escyv -pky21m1 -e 'create database escyv_cyv;'
#here the script restores the database
mysql -u escyv_cyv -pky21m1 escyv_cyv < 0db0/escyv_db.sql
echo "Restaurando Base de Datos..";
echo "Base de datos restaurada!";
這是您自己的本地服務器還是託管的服務器。如果它是第三方託管的服務器,一般情況下,除非您擁有正確的權限,否則無法進行數據庫刪除。創建數據庫也是如此。這主要是出於安全原因。但我不確定這是否是你的情況。 – itsols
hello @itsols在gator託管一個,我有權限,因爲我可以壓縮整個文件夾和備份分區 –
'DROP DATABASE'是單獨的權限。 – AmazingDreams