External wpdb connections in different plugins on single page

You’ll have to make the variable global when you define it, e.g.

global $mydb;
$mydb = new wpdb('username','password','database','localhost');

and then use global $mydb; in the other plugins. Aside from theme files, functions.php, and plugins while being loaded, pretty much nothing in WP runs in global context, so if you need to access global variables, you’ll have to use global.

tech