Query to get term id using post id?

It is not good practice to use query when you have already builtin functions but for your need.

Try this solution:

global $wpdb;
$meta = $wpdb->get_row( "SELECT * FROM `wp_postmeta`  WHERE `meta_id` = $id" );

//will return same object like returned by get_metadata_by_mid() function
print_r($meta);

Debugging Technique:

As you mentioned, get_metadata_by_mid() isn’t working on live server. I would say,

  1. Select any post id (for testing)
  2. Login to phpmyadmin
  3. Run this search query

    SELECT *  FROM `wp_postmeta` WHERE `meta_id` = ID_GOES_HERE
    //copy post_id from the results
    
  4. Run this query

    SELECT *  FROM `wp_terms` WHERE `term_id` = POST_ID_GOES_HERE
    

Try to match the process on both (local & live) server. Hopefully, it will help you identify problem.