how to ugrade mysql version from 5.7 to 8.0

This commit is contained in:
val 2025-06-10 18:36:38 +02:00
parent 71538b15a5
commit 4954511131
No known key found for this signature in database
GPG Key ID: 650507CF2C02830C

View File

@ -0,0 +1,41 @@
# Attention!!!
Recipe updates MySQL version from 5.7 to 8.0 as it is the only supported version of ghost:
https://ghost.org/docs/faq/supported-databases/
This makes a manual migration necessary.
This one worked for me.
Although you create a database-backup. Better to make sure you have a full backup before.
## Follow these steps:
# set your env-var to APP_URL to not have to repeat yourself
APP_URL=queerit.org
# First make a full backup of database
abra app run "$APP_URL" db -t -- mysqldump -u root -pghost ghost > ~/.abra/backups/"$APP_URL"_pre_upgrade_to_mysql_8.sql 2>/dev/null
# undeploy
abra app undeploy "$APP_URL"
# delete database volume
abra app volume rm "$APP_URL"
# -> press "left" to deselect all, then "up"/"down" to find the volume, "space" to select "foo_bar_com_mysql, "enter" to confirm
# redeploy (with the current recipe, db version 8.0 - will recreate database volume
# attention: because the app service is restarted as well, it will reinitialize soon the database
# this can lead to errors when restoring the database. I ran into: ERROR 1050 (42S01) at line 1147: Table 'members_stripe_customers_subscriptions' already exists
# solved it be deleting the volume again and restoring the databse as soon as possible after redeploying
abra app deploy "$APP_URL"
# restore database
abra app run "$APP_URL" db -t -- mysql -u root -pghost ghost < ~/.abra/backups/"$APP_URL"_pre_upgrade_to_mysql_8.sql
# correct db by creating ALTER TABLE commands like its described here: https://ghost.org/docs/faq/supported-databases/
echo "SET foreign_key_checks=0;" > ~/.abra/backups/"$APP_URL"_alter_table.sql
abra app run ghost.dev.local-it.cloud db -t -- mysql -u root -pghost ghost -B --disable-column-names -e 'SELECT CONCAT("ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; ", "ALTER TABLE ",TABLE_SCHEMA,".",TABLE_NAME," CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;") AS alter_sql FROM information_schema.TABLES WHERE TABLE_SCHEMA = database();' >> ~/.abra/backups/"$APP_URL"_alter_table.sql 2>/dev/null
echo "SET foreign_key_checks=1;" >> ~/.abra/backups/"$APP_URL"_alter_table.sql
# run these alter_table.sql commands
abra app run "$APP_URL" db -t -- mysql -u root -pghost ghost < ~/.abra/backups/"$APP_URL"_alter_table.sql