Never share a MySQL connection over several threads. You will cause race conditions. Each thread could (and inevitably does) receive results for queries started on another thread, and this happens unpredictably. You end up with each thread receiving an unintelligible subset of the packets it wants, combined with extra packets it doesn't want.
Also, you mention multi-query but you should not use this either. Execute one statement per call. There's no advantage to using multi-query, if your network is anything close to reasonable performance.
You can be assured that setting or reading user-defined variables like you show in your example is reliable on separate calls to query(), as long as you do it on the same connection.
Regarding node.js, it only allows one statement per request by default. You can enable multipleStatements
(see node-mysql multiple statement in one query) if you want.
The alternative is to run statements one at a time, and run them in serial. You can ensure the next statement waits for the prior one to finish by running it in the callback function for the prior statement. An example is shown in the OP's question in node-mysql multiple statement in one query.