Skip to content

Commit c7dfbcf

Browse files
committed
Document new changeUser functionality
1 parent 13cdd04 commit c7dfbcf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,30 @@ connection.destroy();
184184

185185
Unlike `end()` the `destroy()` method does not take a callback argument.
186186

187+
## Switching users / altering connection state
188+
189+
MySQL offers a changeUser command that allows you to alter the current user and
190+
other aspects of the connection without shutting down the underlaying socket:
191+
192+
```js
193+
connection.changeUser({user : 'john'}, function(err) {
194+
if (err) throw err;
195+
});
196+
```
197+
198+
The available options for this feature are:
199+
200+
* `user`: The name of the new user (defaults to the previous one).
201+
* `password`: The password of the new user (defaults to the previous one).
202+
* `charset`: The new charset (defaults to the previous one).
203+
* `database`: The new database (defaults to the previous one).
204+
205+
A sometimes useful side effect of this functionality is that this function also
206+
resets any connection state (variables, transactions, etc.).
207+
208+
Errors encountered during this operation are treated as fatal connection errors
209+
by this module.
210+
187211
## Server disconnects
188212

189213
You may loose the connection to a MySQL server due to network problems, the

0 commit comments

Comments
 (0)