Create a shell script that runs to turn all database tables in mariadb to character set utf8mb4

anonymous·2023년 1월 30일
0
#!/bin/bash

# specify the database name
db_name="data"

# list all the tables in the database
tables=$(mysql -u root -p"password" -D $db_name -e "SHOW TABLES;" | awk '{print $1}' | grep -v "^Tables")

# loop through each table and convert it to utf8mb4
for table in $tables; do
  mysql -u root -p"password" -D $db_name -e "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
done

# verify the change
mysql -u root -p"password" -D $db_name -e "SELECT TABLE_NAME,TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_SCHEMA = '$db_name';"

Reference

https://chat.openai.com/chat

profile
기술블로거입니다

0개의 댓글

Powered by GraphCDN, the GraphQL CDN