Архив

Архив Март 2020
10 марта 2020 Нет комментариев

shell скрипт для автоматического изменения кодировки таблиц и столбцов с utf8 на utf8mb4

#!/bin/bash
 
# mycollate.sh <database> [<charset> <collation>]
# changes MySQL/MariaDB charset and collation for one database - all tables and
# all columns in all tables
 
DB="$1"
CHARSET="$2"
COLL="$3"
 
AUTH="-uuser -ppass"
 
[ -n "$DB" ] || exit 1
[ -n "$CHARSET" ] || CHARSET="utf8mb4"
[ -n "$COLL" ] || COLL="utf8mb4_general_ci"
 
echo $DB
echo "ALTER DATABASE \`$DB\` CHARACTER SET $CHARSET COLLATE $COLL;" | mysql $AUTH
 
echo "USE \`$DB\`; SHOW TABLES;" | mysql -s $AUTH | (
	while read TABLE; do
		echo $DB.$TABLE
		echo "ALTER TABLE \`$TABLE\` CONVERT TO CHARACTER SET $CHARSET COLLATE $COLL;" | mysql $AUTH $DB
	done
)

https://dba.stackexchange.com/questions/8239/how-to-easily-convert-utf8-tables-to-utf8mb4-in-mysql-5-5

Categories: Mac, Unix Tags: ,