作为运维人员或者开发人员,日常的mysql运维工作我们是一定要会的,我收集了一些常用shell脚本,仅供参考!
#!/bin/bash
BACKUP_DIR="backup_dir"
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
DATABASE="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="mysql_user"
MYSQL_PASSWORD="mysql_password"
DATABASE="database_name"
mysqlcheck?-u?$MYSQL_USER?-p$MYSQL_PASSWORD?--auto-repair?--optimize?$DATABASE
#!/bin/bash
BACKUP_DIR="backup_dir"
DAYS_TO_KEEP=7
find?$BACKUP_DIR?-type?f?-mtime?+$DAYS_TO_KEEP?-exec?rm?{}?\;
#!/bin/bash
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
mysqladmin?-u?$MYSQL_USER?-p$MYSQL_PASSWORD?processlist
#!/bin/bash
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
mysqladmin?-u?$MYSQL_USER?-p$MYSQL_PASSWORD?extended-status
#!/bin/bash
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
DATABASE="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="mysql_user"
MYSQL_PASSWORD="mysql_password"
DATABASE="database_name"
mysqldump?-u?$MYSQL_USER?-p$MYSQL_PASSWORD?--no-data?$DATABASE?>?schema.sql
#!/bin/bash
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
DATABASE="database_name"
mysql?-u?$MYSQL_USER?-p$MYSQL_PASSWORD?$DATABASE?<?schema.sql
#!/bin/bash
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
mysql?-u?$MYSQL_USER?-p$MYSQL_PASSWORD?-e?"FLUSH?TABLES?WITH?READ?LOCK;"
#!/bin/bash
MYSQL_USER="mysql_user"
MYSQL_PASSWORD="mysql_password"
mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -e "UNLOCK TABLES;"
TIPS:在使用这些脚本之前,你需要替换占位符(mysql_user、mysql_password、database_name、backup_dir等)为适当的值。