#!/bin/bash
BACKUP_DIR="/path/to/backup/directory"
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
DATABASE="your_database_name"
DATE=$(date +%Y%m%d%H%M%S)
mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD $DATABASE > $BACKUP_DIR/$DATABASE-$DATE.sql
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
DATABASE="your_database_name"
mysqlcheck -u $MYSQL_USER -p$MYSQL_PASSWORD --auto-repair --optimize $DATABASE
#!/bin/bash
BACKUP_DIR="/path/to/backup/directory"
DAYS_TO_KEEP=7
find $BACKUP_DIR -type f -mtime +$DAYS_TO_KEEP -exec rm {} \;
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
mysqladmin -u $MYSQL_USER -p$MYSQL_PASSWORD processlist
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
mysqladmin -u $MYSQL_USER -p$MYSQL_PASSWORD extended-status
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
DATABASE="your_database_name"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "SELECT table_schema AS 'Database Name', SUM(data_length + index_length) / 1024 / 1024 AS 'Size (MB)' FROM information_schema.TABLES GROUP BY table_schema;"
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
DATABASE="your_database_name"
mysqldump -u $MYSQL_USER -p$MYSQL_PASSWORD --no-data $DATABASE > schema.sql
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
DATABASE="your_database_name"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $DATABASE < schema.sql
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "FLUSH TABLES WITH READ LOCK;"
#!/bin/bash
MYSQL_USER="your_mysql_user"
MYSQL_PASSWORD="your_mysql_password"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "UNLOCK TABLES;"
END
来源:入门小站