Table of Contents

mysql_change_user

my_bool mysql_change_user(MYSQL *mysql, const char *user, const char *password, const char *db)

description of mysql_change_user

mysql_change_user is used to change the current user for the actual connection

#include <stdio.h> /* including standard library */ 
#include <mysql/mysql.h>
 
MYSQL *my;
MYSQL_ROW  row;
MYSQL_RES  *mysql_res; 
 
int main( void ){
char host[20];
char user[20];
char pass[20];
 
my = mysql_init(NULL);
 
 
sprintf(host,"localhost");
sprintf(user,"username");
sprintf(pass,"password");
 
if (my == NULL ) {
printf("Cant initalisize MySQL\n");
return 1;
}
 
if( mysql_real_connect (my,host,user,pass,NULL,0,NULL,0)  == NULL) {
  printf("Error cant login\n");
  } else {
  printf("Login correct\n");
  }
 
 mysql_select_db(my,"test");
 
 
if (mysql_change_user(my, "root", "somepass", "other_database"))
{
   fprintf(stderr, "Failed to change user.  Error: %s\n",
           mysql_error(my));
} else {
   printf("change user successfully\n");
}
 
mysql_close(my);
return 0;
}

output of mysql_change_user c example

  Login correct
  change user successfully