Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -eu
- MYSQL_USERNAME="root"
- MYSQL_PASSWORD="123admin_123"
- FILTRO_BBDD=""
- FILTRO_TABLA=""
- while [[ ! -z "${1-}" ]]; do
- case "${1-}" in
- --bbdd=*)
- FILTRO_BBDD="AND table_schema = '${1#*=}'"
- shift
- ;;
- --tabla=*)
- FILTRO_TABLA="AND table_name = '${1#*=}'"
- shift
- ;;
- *)
- echo >&2 "WARN: Parametro desconocido: $1"
- shift
- ;;
- esac
- done
- mysql "--user=${MYSQL_USERNAME}" "--password=${MYSQL_PASSWORD}" -bs -e "SELECT CONCAT('\`', REPLACE(table_schema, '\`', '\`\`'), '\`.\`', REPLACE(table_name, '\`', '\`\`'), '\`') FROM information_schema.tables WHERE 1=1 ${FILTRO_BBDD} ${FILTRO_TABLA}" | while read tabla; do
- mysql "--user=${MYSQL_USERNAME}" "--password=${MYSQL_PASSWORD}" -s -e "ANALYZE TABLE ${tabla}"
- done
- mysql "--user=${MYSQL_USERNAME}" "--password=${MYSQL_PASSWORD}" -bs -e "SELECT CONCAT('\`', REPLACE(table_schema, '\`', '\`\`'), '\`.\`', REPLACE(table_name, '\`', '\`\`'), '\`') FROM information_schema.tables WHERE 1=1 ${FILTRO_BBDD} ${FILTRO_TABLA} AND engine <> 'InnoDB'" | while read tabla; do
- mysql "--user=${MYSQL_USERNAME}" "--password=${MYSQL_PASSWORD}" -s -e "OPTIMIZE TABLE ${tabla}"
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement