mysqlsqldatabasecronautomated-deploy

how do i automated MySQL data base restore everyday with crontab?


i have some demo website user can register and login and share post add products with some function but its for demo purpose only so daily 10 to 15 people register and test how its work

but i don't need everyone data i have new mysql.sql file in this SQL don't have any much data i want to do automate task with crone tab

every day its will delete current database and upload my mysql.sql file

how can i do this?

os:ubuntu 19.04


Solution

  • Since all you want to do is "reinstall" your DB on a daily basis (is that correct?). You can add to your install script on the first line:

              DROP database <your databese>
              # Here you re-create your DB again (your current sql script)
    

    Let's say you call this script "reinstall.sql"; you can add to your cron table the following line (which runs the command everyday @ 1am):

     0 1 * * *  mysql -u username -p password database_name < /path/to/your/reinstall.sql
    

    To open the cron table you can do this:

     sudo crontab -l -u [USER_WITH_RIGHTS_TO_EDIT]
    

    Hope it helps!