Name
mysql_change_user —
Synopsis
my_bool mysql_change_user(MYSQL *mysql, char *username, char *password, char *database)
Changes the currently authenticated user
and database. This function reauthenticates the current connection
using the given username and password. It also changes the default
database to the given database (which can be NULL
if no default is desired). If the password is incorrect for the given
username, or if the new user does not have rights to access the given
database, a false
value is returned, and no action
is taken. Otherwise, the rights of the new user take effect, the
default database is selected, and a true
value is
returned.
Example
if (! mysql_change_user( &mysql, new_user, new_pass, new_db ) ) { printf("Change of User unsuccessful!"); exit(1); } /* At this point, the connection is operating under the access rights of the new username, and the new database is the default. */
Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.