How to Reset MySQL database with time limit using php

Problem :

I have a demo website for the users. It contain database with few tables. I want to reset the entire database with time frame using PHP.

How can I truncate all the tables every hour?

Solution :

Truncating every table wouldn't work in this case because some of the tables will contain initial configuration data.

I would set up the basic system exactly as you want it. Then do a one off database dump and a tarball back up of the moodledata directory.

Also create a file in moodledata called old_climaintenance.html with a message for users while the site is offline.

Then set up a bash script to go through these steps

  1. Rename old_climaintenance.html to climaintenance.html to let users know its offline.
  2. Drop the database
  3. Delete the contents of the moodledata directory - except old_climaintenance.html
  4. Restore the tarball into moodledata
  5. Recreate the database from the data dump
  6. Rename climaintenance.html to old_climaintenance.html

Then set up a cron job to run the bash script every hour.

Mysql Tutorials

Mysql Howto..

How to see errors in MySQL Workbench 6.1?

How to avoid stale MySQL/Hibernate connections (MySQLNonTransientConnectionException)

how to apply FIND WHOLE WORD ONLY in mysql query

How do I make a MySQL query that's equivalent to Fusion Tables “summarize” function?

How to grab the last three rows in MySQL

How to interact with 2 databases in C using MySQL?

How to get the last result from a MYSQL query using PHP PDO?

How to insert norman date in mysql using php?

MySQL - How to refer to server as http path?

How to use GROUP_CONCAT in a CONCAT in mysql

How to insert records from a database into another database table?

How do relational databases fetch the unindexed columns?

How to get data from multiple tables of MySQL DB and manuplate it using PHP to display graphs?

PHP PDO How to keep just one MYSQL connection [closed]

How to insert timestamp into mysql with php properly?

How to deploy local MySQL database to Heroku

SQL / MySQL - how to get a unique week number (independent of the year)?

How to use subqueries in MySQL

how to create index with accent in MySQL

How to get data from mysql database only for this year

MySQL Workbench - How to get results from multiple where clauses?

how to make mysql sub query

How to save combobox content into mysql table?

How can I get UTF8 to work correctly using mysql and php?

How to get this specific user rankings query in mysql?

How to select data from multiple tables and display them in a json format? [closed]

How to relate images in a folder to its metadata stored in mysql in perl?

How to do this in MySQL: if field value > 0 then minus one, else let it be

How to insert data in child table(Tb1) of parent table(Tb2) that is also the parent(Tb2) of child(Tb1) in MySQL?

How to populate sql query result in a series of chained select boxes?