Linux下最最常用的MySQL运维脚本

2023-08-29 12:41:40     来源:面包芯语


(资料图)

#!/bin/bashBACKUP_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/bashMYSQL_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/bashBACKUP_DIR="/path/to/backup/directory"DAYS_TO_KEEP=7find$BACKUP_DIR-typef-mtime+$DAYS_TO_KEEP-execrm{}\;
#!/bin/bashMYSQL_USER="your_mysql_user"MYSQL_PASSWORD="your_mysql_password"mysqladmin-u$MYSQL_USER-p$MYSQL_PASSWORDprocesslist
#!/bin/bashMYSQL_USER="your_mysql_user"MYSQL_PASSWORD="your_mysql_password"mysqladmin-u$MYSQL_USER-p$MYSQL_PASSWORDextended-status
#!/bin/bashMYSQL_USER="your_mysql_user"MYSQL_PASSWORD="your_mysql_password"DATABASE="your_database_name"mysql-u$MYSQL_USER-p$MYSQL_PASSWORD-e"SELECTtable_schemaAS"DatabaseName",SUM(data_length+index_length)/1024/1024AS"Size(MB)"FROMinformation_schema.TABLESGROUPBYtable_schema;"
#!/bin/bashMYSQL_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/bashMYSQL_USER="your_mysql_user"MYSQL_PASSWORD="your_mysql_password"DATABASE="your_database_name"mysql-u$MYSQL_USER-p$MYSQL_PASSWORD$DATABASE
#!/bin/bashMYSQL_USER="your_mysql_user"MYSQL_PASSWORD="your_mysql_password"mysql-u$MYSQL_USER-p$MYSQL_PASSWORD-e"FLUSHTABLESWITHREADLOCK;"
#!/bin/bashMYSQL_USER="your_mysql_user"MYSQL_PASSWORD="your_mysql_password"mysql-u$MYSQL_USER-p$MYSQL_PASSWORD-e"UNLOCKTABLES;"

来源:入门小站

标签:

包装