You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-3Lines changed: 36 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,6 +177,41 @@ let connection = mysql.getClient()
177
177
let value =connection.escape('Some value to be escaped')
178
178
```
179
179
180
+
You can change the user of an existing connection using the `changeUser()` method. This is useful when you need to switch to a different MySQL user with different permissions.
181
+
182
+
```javascript
183
+
// Change to a different user
184
+
awaitmysql.changeUser({
185
+
user:'newuser',
186
+
password:'newpassword'
187
+
})
188
+
189
+
// Now queries will be executed as the new user
190
+
let results =awaitmysql.query('SELECT * FROM restricted_table')
191
+
```
192
+
193
+
You can also use the `changeUser()` method to change the current database, which is equivalent to the `USE DATABASE` SQL statement:
194
+
195
+
```javascript
196
+
// Change to a different database
197
+
awaitmysql.changeUser({
198
+
database:'new_database'// Change the database only
199
+
})
200
+
201
+
// Now queries will be executed against the new database
202
+
let results =awaitmysql.query('SELECT * FROM new_database_table')
203
+
```
204
+
205
+
Alternatively, you can use the standard SQL `USE DATABASE` statement with the `query()` method:
206
+
207
+
```javascript
208
+
// Change to a different database using SQL
209
+
awaitmysql.query('USE new_database')
210
+
211
+
// Now queries will be executed against the new database
212
+
let results =awaitmysql.query('SELECT * FROM new_database_table')
213
+
```
214
+
180
215
## Configuration Options
181
216
182
217
There are two ways to provide a configuration.
@@ -357,6 +392,4 @@ Other tests that use larger configurations were extremely successful too, but I'
357
392
Contributions, ideas and bug reports are welcome and greatly appreciated. Please add [issues](https://github.com/jeremydaly/serverless-mysql/issues) for suggestions and bug reports or create a pull request.
0 commit comments