davidz Posted March 26, 2007 Share Posted March 26, 2007 I am currently running a cron job that dumps my MYSQL databases every night with a command like this: mysqldump --opt -uUsername -pPassword DBName > /home/sqldump/DBName.sql This is working great, and I've even restored from it successfully a couple times. But now the files are getting too large. My main database is over 3 gigs when its dumped. So what I want to do is dump each individual table to separate .sql files. But I don't want to have some list that I have to maintain. I found this bit of code that is close: echo "SHOW TABLES" | mysql -uUsername -pPassword -D DBName | grep ^tablename | xargs mysqldump -uUsername -pPassword DBName > /home/sqldump/tablename.sql Does anyone have a better solution that does not require a tablename, or dynamically gets the list of table names? Thanks!! David Quote Link to comment https://forums.phpfreaks.com/topic/44347-individual-table-backup/ Share on other sites More sharing options...
fenway Posted April 4, 2007 Share Posted April 4, 2007 First, you should be wary of putting the password in plaintext, since it will be visible in log files, top, etc.... but SHOW TABLES is "dynamic", so to speak... besides, only MyISAM tables are individual (well, new innodb has table-based datafiles, too, but you can't mysqldump them easily). Quote Link to comment https://forums.phpfreaks.com/topic/44347-individual-table-backup/#findComment-221149 Share on other sites More sharing options...
davidz Posted April 4, 2007 Author Share Posted April 4, 2007 Thanks for the tip on the password issue, I'll come up with something there. As for the tables, we use all MyISAM tables, so that's not a problem. How about this, use the command: echo "SHOW TABLES" |mysql -uUSERNAME -pPASSWORD -D DBNAME This will produce output like the following: Tables_in_DBNAME tblUserData tblUserPrefs tblStats ...This will list all the tables in the DB. So what I can then do is drop this output to a file instead: echo "SHOW TABLES" |mysql -uUSERNAME -pPASSWORD -D DBNAME > tablelist Then use perl to go through the file 'tablelist' line by line (skipping the first line) and perform: mysqldump -uUSERNAME -pPASSWORD DBNAME > $tablename.sql Substituting $tablename for the line that I'm on. Thanks for the input! Quote Link to comment https://forums.phpfreaks.com/topic/44347-individual-table-backup/#findComment-221630 Share on other sites More sharing options...
fenway Posted April 5, 2007 Share Posted April 5, 2007 I'm pretty sure you can read the password from a cnf file. Quote Link to comment https://forums.phpfreaks.com/topic/44347-individual-table-backup/#findComment-222261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.