Skip to content

Instantly share code, notes, and snippets.

@schelmo
Created March 28, 2020 11:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schelmo/4b4954b7137199aa1058681ce41d145a to your computer and use it in GitHub Desktop.
Save schelmo/4b4954b7137199aa1058681ce41d145a to your computer and use it in GitHub Desktop.
convert all innodb tables to dynamic
#!/bin/bash
umask 0177
temp_file=$(mktemp)
trap 'rm -f -- "$temp_file"' INT TERM HUP EXIT
read -sp 'mysql root password: ' passvar
echo "
[client]
user=root
password='${passvar}'
" > $temp_file
for table in $(
mariadb \
--defaults-extra-file="$temp_file" \
--batch --skip-column-names \
--execute="
SELECT CONCAT('\`', TABLE_SCHEMA, '\`', '.', '\`', TABLE_NAME, '\`')
FROM information_schema.TABLES
WHERE ENGINE = 'InnoDB'
AND ROW_FORMAT IN('Redundant', 'Compact')
AND TABLE_NAME NOT IN(
'SYS_DATAFILES', 'SYS_FOREIGN',
'SYS_FOREIGN_COLS', 'SYS_TABLESPACES',
'SYS_VIRTUAL', 'SYS_ZIP_DICT',
'SYS_ZIP_DICT_COLS'
)
AND TABLE_SCHEMA NOT IN(
'piwik_stats', 'mysql'
)
;"
)
do
alter_sql="ALTER TABLE ${table} ROW_FORMAT=DYNAMIC;";
echo $alter_sql
mariadb --defaults-extra-file="$temp_file" --execute="${alter_sql}"
done
@schelmo
Copy link
Author

schelmo commented Mar 28, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment