Dynamic Settings on MQTT Node

You need to send msg.action and msg.broker with broker, port ,username and password to connect. To disconnect you just need to send msg.action
e.g.

[{"id":"989ce477843d6ccb","type":"inject","z":"d1395164b4eec73e","name":"connect","props":[{"p":"action","v":"connect","vt":"str"},{"p":"broker","v":"{\"broker\":\"192.168.1.25\",\"port\":1883,\"password\":\"\",\"username\":\"\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":370,"y":7640,"wires":[["a8750ccc1e9f1a78","43c3fe97cfaf9f04"]]},{"id":"a8750ccc1e9f1a78","type":"mqtt out","z":"d1395164b4eec73e","name":"","topic":"","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"e8ba3ef5.22f4a8","x":610,"y":7640,"wires":[]},{"id":"43c3fe97cfaf9f04","type":"debug","z":"d1395164b4eec73e","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":7720,"wires":[]},{"id":"c67446f710eaae5a","type":"inject","z":"d1395164b4eec73e","name":"disconnect","props":[{"p":"action","v":"disconnect","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":340,"y":7700,"wires":[["a8750ccc1e9f1a78","43c3fe97cfaf9f04"]]},{"id":"e8ba3ef5.22f4a8","type":"mqtt-broker","name":"testb","broker":"192.168.1.25","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

Add you broker and user and password in the inject node.

Here is another example flow that demonstrates most dynamic mqtt features Dynamic MQTT node's "actions->connect" guidance needed - #2 by Steve-Mcl