Which way should be selected when move from mysql to mariadb?
We can't do anything without a problem except point you to the official information,


How to migrate from MySQL to MariaDB on Linux in five steps
Migrating to MariaDB


Generally the further you are from an original fork the more complexities you'll encounter in the migration. Therefore the earlier the version of MySQL the fewer features of MySQL that are MySQL-specific that you'll have to contend with. Upgrading to a newer of MySQL before the migration to MariaDB is likely to make your job harder.