Replace SQL db with another every hour
Hi all,
How can I replace SQL database with another one via Cron every hour?
Context: I'm trying to create a Wordpress demo site and setup cron job to replace modified database with the original repeatedly.
If anyone has the command example and where to place original SQL db I'd really appreciate the help.
Thank you
-
Hey there! I believe this should be doable as long as the user has shell access enabled. This would let the user have access to mysql on the command line, allowing them to import the database from a cron. I tested this on my end by doing the following: -placed the original database.sql in the /home/username directory -ensured the cPanel user has shell access After that, I created the database and ensured there was a user that could access it. I was then able to run this command from a Bash script to update the database: mysql -u username_testuser -p PASSWORD-GOES-HERE username_testdb < original_db.sql
That Bash script would then just get called hourly by the cron job. I would expect that to work just as well on your end, but let me know if you run into issues.0 -
Hey there! I believe this should be doable as long as the user has shell access enabled. This would let the user have access to mysql on the command line, allowing them to import the database from a cron. I tested this on my end by doing the following: -placed the original database.sql in the /home/username directory -ensured the cPanel user has shell access After that, I created the database and ensured there was a user that could access it. I was then able to run this command from a Bash script to update the database:
mysql -u username_testuser -p PASSWORD-GOES-HERE username_testdb < original_db.sql
That Bash script would then just get called hourly by the cron job. I would expect that to work just as well on your end, but let me know if you run into issues.
Thank you for this, but I only have Reseller account without the Shell access in this scenario, is there a way to pull this off somehow or should I contact Hosting company to implement this for me?0 -
These commands would actually be run as the cPanel user on the account, so your reseller status wouldn't matter. 0
Please sign in to leave a comment.
Comments
3 comments