Proper way to edit a post via phpMyAdmin without breaking the compare revisions tool

The reason there’s a hole is because revision history isn’t a history of SQL changes. Each revision is represented in the database as a post of type revision. For your changes to be shown, an additional revision post would be needed.

To do this, you’ll need to update the post via PHP rather than SQL. You could do this via the interface, the REST API, calling wp_update_post, but for bulk processing I would recommend using WP CLI. Something similar to the following:

CONTENT=$(wp post get 123 --field=content)
.. adjust CONTENT to do your search replace ( maybe with sed or awk? )
wp post update 123 --post_content="$CONTENT"

https://developer.wordpress.org/cli/commands/post/update/
https://developer.wordpress.org/cli/commands/post/get/

Then just fetch every post and loop over them running the above. This will ensure all the hooks and filters get fired. It’s not as quick as an SQL query but it works.

You might also want to use the search replace command instead of raw SQL to directly swap strings in the database, as it handles serialized PHP correctly in options and post meta