I am new to mysql so forgive me if the solution to my problem is obvious. I have a mysql database that has a number of tables that I need to archive. A number of the tables have over 1000000 rows. I have 11 tables that I am archiving and then deleting from.
A snippet from my code would be :
set @archive_before_date='2010-10-01'
create table if not exists archive_prescription as
select * from prescription where prescriptiondate < @archive_before_date;
delete from prescription where prescriptiondate < @archive_before_date;
I am currently using mysql browser and I am running the script in the script tab. When I run the script the mysql query browser shows in task manager as not responding and mysql administrator shows only the first two archive tables. On a database with the same schema and less data the script works perfectly.
Does anyone have any hints as how to best approach this problem?
Copy the script into a file and save it to disk.
Then run mysql -u -p < yoursavescriptname
This will read the commands in from the script and execute them in turn.
This command line itself could be placed in a .bat file on Windows, or an executable .sh file on *nix.
Also you could place several mysql etc. < filename lines in the same .bat files.
If you wanted to run this at a certain time you could then reference the .sh file from a cron entry. however, if doing this add an env in the .sh file somewhere, and redirect the output to a file as cron runs with a different environment to a logged in user.