Database maintenance from console.
Explained in Handling Mysql Credentials From Linux Command Line The Right Way
Database maintenance from console.
Explained in Handling Mysql Credentials From Linux Command Line The Right Way
#!/bin/bash | |
# Backup database from console | |
DATABASE= | |
DEFAULTS_FILE=$DATABASE.cnf | |
BACKUP_DIR= | |
LOGS_DIR= | |
DB_OUT_FILENAME=$DEFAULTS_FILE-`date +\%Y\%m\%d`.sql.gz | |
mysqldump --defaults-extra-file=$DEFAULTS_FILE $DATABASE 2>> $LOGS_DIR/$DATABASE.log | gzip - > $BACKUP_DIR/$DB_OUT_FILENAME |
[client] | |
host= | |
user= | |
password= | |
#!/bin/bash | |
# Truncate database tables from console | |
DATABASE= | |
DEFAULTS_FILE=$DATABASE.cnf | |
mysql --defaults-extra-file="$DEFAULTS_FILE" -Nse 'show tables' $DATABASE | while read table; do mysql --defaults-extra-file="$DEFAULTS_FILE" -e "truncate table $table" $DATABASE; done |