You can call the mysql_ssl_set() function to establish an encrypted connection by using SSL.
Syntax
my_bool
mysql_ssl_set(MYSQL *mysql,
const char *key,
const char *cert,
const char *ca,
const char *capath,
const char *cipher)
Arguments
mysql: the connection handler returned frommysql_init().mysqlmust be a valid connection handler. Any unused SSL argument can be set toNULL.key: the path name of the client private key file.cert: the path name of the client public key certificate file.ca: the path name of the CA certificate file. If this option is used, it must specify the same certificate as the server.capath: the path name of the directory that contains trusted SSL CA certificate files.cipher: the list of passwords used for SSL encryption.
Return values
This function always returns 0. If SSL is incorrectly set, a subsequent mysql_real_connect() call returns an error.
Notes
mysql_ssl_set() must be called before mysql_real_connect(). mysql_ssl_set() works only after SSL is enabled in the client library.
mysql_ssl_set() specifies SSL information such as the certificate and key files for establishing an encrypted connection (if such connections are available), but does not require that the connection obtained be encrypted.
mysql_ssl_set() is essentially equivalent to the following set of mysql_options() calls:
mysql_options(mysql, MYSQL_OPT_SSL_KEY, key);
mysql_options(mysql, MYSQL_OPT_SSL_CERT, cert);
mysql_options(mysql, MYSQL_OPT_SSL_CA, ca);
mysql_options(mysql, MYSQL_OPT_SSL_CAPATH, capath);
mysql_options(mysql, MYSQL_OPT_SSL_CIPHER, cipher);
Therefore, applications can directly call mysql_options() instead ofmysql_ssl_set(), omitting calls to options with the value NULL. Moreover, mysql_options() provides encrypted-connection options not available in mysql_ssl_set(), such as MYSQL_OPT_SSL_MODE for specifying the security status of the connection.