@@ -155,7 +155,8 @@ static char * opt_mysql_unix_port=0;
155155static int connect_flag=CLIENT_INTERACTIVE;
156156static char *current_host,*current_db,*current_user=0 ,*opt_password=0 ,
157157 *current_prompt=0 , *delimiter_str= 0 ,
158- *default_charset= (char *) MYSQL_DEFAULT_CHARSET_NAME;
158+ *default_charset= (char *) MYSQL_DEFAULT_CHARSET_NAME,
159+ *opt_init_command= 0 ;
159160static char *histfile;
160161static char *histfile_tmp;
161162static String glob_buffer,old_buffer;
@@ -1384,6 +1385,10 @@ static struct my_option my_long_options[] =
13841385 {" ignore-spaces" , ' i' , " Ignore space after function names." ,
13851386 (uchar**) &ignore_spaces, (uchar**) &ignore_spaces, 0 , GET_BOOL, NO_ARG, 0 , 0 ,
13861387 0 , 0 , 0 , 0 },
1388+ {" init-command" , OPT_INIT_COMMAND,
1389+ " SQL Command to execute when connecting to MySQL server. Will automatically be re-executed when reconnecting." ,
1390+ (uchar**) &opt_init_command, (uchar**) &opt_init_command, 0 ,
1391+ GET_STR, REQUIRED_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
13871392 {" local-infile" , OPT_LOCAL_INFILE, " Enable/disable LOAD DATA LOCAL INFILE." ,
13881393 (uchar**) &opt_local_infile,
13891394 (uchar**) &opt_local_infile, 0 , GET_BOOL, OPT_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
@@ -4203,6 +4208,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
42034208 mysql_close (&mysql);
42044209 }
42054210 mysql_init (&mysql);
4211+ if (opt_init_command)
4212+ mysql_options (&mysql, MYSQL_INIT_COMMAND, opt_init_command);
42064213 if (opt_connect_timeout)
42074214 {
42084215 uint timeout=opt_connect_timeout;
0 commit comments