23.8.7.3 mysql_change_user()

Description

Changes the user and causes the database specified by
db to become the default (current) database
on the connection specified by mysql. In
subsequent queries, this database is the default for table
references that include no explicit database specifier.

mysql_change_user() fails if
the connected user cannot be authenticated or does not have
permission to use the database. In this case, the user and
database are not changed.

Pass a db parameter of
NULL if you do not want to have a default
database.

This function resets the session state as if one had done a
new connect and reauthenticated. (See
Section 23.8.20, “C API Automatic Reconnection Control”.) It always performs a
ROLLBACK of
any active transactions, closes and drops all temporary
tables, and unlocks all locked tables. Session system
variables are reset to the values of the corresponding global
system variables. Prepared statements are released and
HANDLER variables are closed.
Locks acquired with GET_LOCK()
are released. These effects occur even if the user did not
change.