the importance is the latest mysql not yet support the SSL in windows platform.This means its SSL just support unix platform.
Note my source is verbose as following while you feel free:
#include
#include
#include
#include
static char *opt_host_name=NULL;
static char *opt_user_name=NULL;
static char *opt_password=NULL;
static unsigned int opt_port_num=0;
static char *opt_socket_name=NULL;
static char *opt_db_name=NULL;
static unsigned int opt_flags=0;
static MYSQL *conn;
static const char *client_groups[]={"client',NULL};
static struct my_option my_opts[]={
{"help",',"Display this help and exit",NULL,NULL,NULL,GET_NO_ARG,NO_ARG,0,0,0,0,0,0},
{"host",'h',"Host to connect to",(gptr *) &opt_host_name,NULL,NULL,GET_STR_ALLOC,REQUIRED_ARG,0,0,0,0,0,0}'
{"password",'p',"Password",(gptr *) &opt_password,NULL,NULL,GET_STR_ALLOC,OPT_ARG,0,0,0,0,0,0},
{"port",'P',"Port number",(gptr *) &opt_port_num,NULL,NULL,GET_UINT,REQUIRED_ARG,0,0,0,0,0,0},
{"SOCKET",'S',"Socket path",(gptr *) &opt_socket_name,NULL,NULL,GET_UINT,REQUIRED_ARG,0,0,0,0,0,0},
{"user",'u',"User name",(gptr *) &opt_user_name,NULL,NULL,GET_UINT,REQUIRED_ARG,0,0,0,0,0,0}
};
void
print_error(MYSQL *conn,char *message)
{
fprintf(stderr,"%sn",message);
if (conn!=NULL)
{
fprintf(stderr,"Error %u (%s)n"'mysql_errno(conn),mysql_error(conn));
}
}
my_bool
get_one_option(int optid,const struct my_option *opt,char *argument)
{
switch(optid)
{
case'?':
my_print_help(my_opt);
exit(0);
case'p':
if(!argument)
ask_password=1;
else
{
opt_password=strdup(argument);
if(opt_password==NULL)
{
print_error(NULL,"could not allocate password buffer");
exit(1);
}
while(*argument)
*argument++='x';
}
break;
#include
}
return(0);
}
int
main(int argc,char *argv[])
{
int opt_err;
my_init();
load_defaults("my",client_groups,&argc,&argv);
if((opt_err=handle_options(&argc,&argv,my_opts,get_one_option)))
exit(opt_err);
if(ask_password)
opt_password=get_tty_password(NULL);
if(argc>0)
{
opt_db_name=argv[0];
--argc;==argv;
}
conn=mysql_init(NULL);
if(conn==NULL)
{
print_error(NULL,"mysql_init() dailed(probably out of memory)");
exit(1);
}
if(mysql_real_connect(conn,opt_host_name,opt_user_name,opt_password,opt_db_name,opt_port_num,opt_socket_name,opt_flags)==NULL)
{
print_error(conn,"mysql_real_connect() failed");
mysql_close(conn);
exit(1);
}
mysql_close(conn);
exit(0);
}
#include
{NULL,0,NULL,NULL,NULL,NULL,GET_NO_ARG,NO_ARG,0,0,0,0,0,0}
};
#ifdef HAVE_OPENSSL
{"ssl",OPT_SLL_SLL,"Enable SSL for connection.Disable with --skip-sll",(gptr*) &opt_use_ssl,NULL,0,GET_BOOL,NO_ARG,0,0,0,0,0,0},
{"ssl-key",OPT_SSL_CERT,"X509 key in PEM format(implies --ssl)",(gptr*) &opt_ssl_key,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-cert",OPT_SSL_CERT,"X509 cert in PEM format(implies --ssl)",(gptr*) &opt_ssl_cert,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-ca",OPT_SSL_CA,"CA file in PEM format(check openSSL docs,implies --sl)",(gptr*) &opt_ssl_ca,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-capath",OPT_SSL_CAPATH,"CA direcory(check openSSL docs,implies --sl)",(gptr*) &opt_ssl_capath,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
{"ssl-cipher",OPT_SSL_CIPHER,"SSLcipher to use(implies --ssl)",(gptr*) &opt_ssl_cipher,NULL,0,GET_STR,REQUIRED_ARG,0,0,0,0,0,0},
#endif
#ifdef HAVE_OPENSSL
eum options
{
OPT_SSL_SSL=256,
OPT_SSL_KEY'
OPT_SSL_CERT,
OPT_SSL_CA,
OPT_SSL_CAPATH,
OPT_SSL_CIPHER
};
#endif
#ifdef HAVE_OPENSSL
static my bool opt_use_ssl=0;
static char *opt_ssl_key=0;
static char *opt_ssl_cert=0;
static char *opt_ssl_ca=0;
static char *opt_ssl_capath=0;
static char *opt_ssl_cipher=0;
#endif
#ifdef HAVE_OPENSSL
case OPT_SSL_KEY:
case OPT_SSL_CERT:
case OPT_SSL_CA:
case OPT_SSL_CAPATH:
case OPT_SSL_CIPHER:
opt_use_ssl=1;
break
#endif
Now put following source to the program sslclient:
conn=mysql_init(NULL);
if(conn==NULL)
{
print_error(NULL,"mysql_init() failed(probably out of memory)");
exit(1);
}
#ifdef HAVE_OPENSSL
if(opt_use_ssl)
mysql_ssl_set(conn,opt_ssl_key,opt_ssl_cert,opt_ssl_ca,opt_ssl_capath,opt_ssl_cipher);
#endif
if(mysql_real_connect(conn,opt_host_name,opt_user_name,_opt_password,opt_db_name,opt_port_num,opt_socket_name,opt_flags)==NULL)
{
print_error(conn,"mysql_real_connect() failed");
mysql_close(conn);
exit(1);
}