It's kind of a hack, and it's not a join, but I use bash functions to make it feel like I'm doing cross-server queries:
The explicit version:
tb2lst(){
echo -n "("
tail -n +2 - | paste -sd, | tr -d "\n"
echo ")"
}
id_list=$(mysql -h'db_a.hostname' -ume -p'ass' -e "SELECT id FROM foo;" | tb2lst)
mysql -h'db_b.hostname' -ume -p'ass' -e "SELECT * FROM bar WHERE foo_id IN $id_list"
+--------|-----+
| foo_id | val |
+--------|-----+
| 1 | 3 |
| 2 | 4 |
+--------|-----+
I wrote some wrapper functions which I keep in my bashrc, so my perspective it's just one command:
db_b "SELECT * FROM bar WHERE foo_id IN $(db_a "SELECT id FROM foo;" | tb2lst);"
+--------|-----+
| foo_id | val |
+--------|-----+
| 1 | 3 |
| 2 | 4 |
+--------|-----+
At least for my use case, this stitches the two queries together quickly enough that the output is equivalent to the join, and then I can pipe the output into whatever tool needs it.
Keep in mind that the id list from one query ends up as query text in the other query. If you "join" too much data this way, your OS might limit the length of query (https://serverfault.com/a/163390). So be aware that this is a poor solution for very large datasets. I have found that doing the same thing with a mysql library like pymysql works around this limitation.