LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-20-2008, 11:32 PM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
mySQL - archive & create new database via cron?


I am looking a way to keep my mysql queries responsive. An approach would be to create a new database every week/month.

Is there a way to automatically dump the current database, name the database (by date), and create the new database, name the database (by date) with the required schema?

regards,
 
Old 04-20-2008, 11:40 PM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Why does creating a new database speed things up - do you keep loads of useless data in there? Sounds like a more fundamental issue than what you've described.
 
Old 04-20-2008, 11:46 PM   #3
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Apologies. There are actually two requirements:

-speed up queries
-archive & split the databases by time (either weekly/monthly). this is for data retention, SOX etc..

regards,
 
Old 04-21-2008, 05:58 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
The date command gives you a date string which you can use in file naming. Like in:
Code:
fname=myfile_$(date +%F)
which produces a file name myfile_2008-04-21.

You can use the mysqldump command to make a dump from the database. See the man page for the numerous options mysqldump provides.

All other commands can be issued from the command line or a Bash script in the form:
Code:
echo "SQL statement" | mysql -u username -ppasswd databasename
I recommend to put all commands in a Bash script, and call the Bash script as a cron job. Be sure to include full paths for everything you call or use in the file, cron jobs run in a different environment than your command line.

jlinkels
 
Old 04-21-2008, 07:13 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Partitioning may be an option. It basically divides tables according to certain rules.
You might need to change / add indexes to speed up your queries.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create mysql user for backup of database timgerr Linux - Server 2 01-04-2008 10:44 AM
Optimize MySQL Database Cron Job Help br00tal Linux - General 3 10-03-2005 04:45 PM
How to create Database in mysql irfanhab Linux - General 1 12-16-2004 06:37 PM
MySQL - command - create user/single database dmedici Linux - Software 3 06-21-2004 03:17 PM
query DNS and create mysql database nabil Programming 0 01-18-2002 04:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration