Struct cdbc_mysql::MySqlConnectOptions[][src]

pub struct MySqlConnectOptions {
    pub host: String,
    pub port: u16,
    pub socket: Option<PathBuf>,
    pub username: String,
    pub password: Option<String>,
    pub database: Option<String>,
    pub ssl_mode: MySqlSslMode,
    pub ssl_ca: Option<CertificateInput>,
    pub statement_cache_capacity: usize,
    pub charset: String,
    pub collation: Option<String>,
}
Expand description

Options and flags which can be used to configure a MySQL connection.

A value of MySqlConnectOptions can be parsed from a connection URI, as described by MySQL.

The generic format of the connection URL:

mysql://[host][/database][?properties]

Properties

ParameterDefaultDescription
ssl-modePREFERREDDetermines whether or with what priority a secure SSL TCP/IP connection will be negotiated. See MySqlSslMode.
ssl-caNoneSets the name of a file containing a list of trusted SSL Certificate Authorities.
statement-cache-capacity100The maximum number of prepared statements stored in the cache. Set to 0 to disable.
socketNonePath to the unix domain socket, which will be used instead of TCP if set.

Example

// URI connection string
let conn = MySqlConnection::connect("mysql://root:password@localhost/db")?;

// Manually-constructed options
let conn = MySqlConnectOptions::new()
    .host("localhost")
    .username("root")
    .password("password")
    .database("db")
    .connect()?;
     Ok(())

Fields

host: Stringport: u16socket: Option<PathBuf>username: Stringpassword: Option<String>database: Option<String>ssl_mode: MySqlSslModessl_ca: Option<CertificateInput>statement_cache_capacity: usizecharset: Stringcollation: Option<String>

Implementations

Creates a new, default set of options ready for configuration

Sets the name of the host to connect to.

The default behavior when the host is not specified, is to connect to localhost.

Sets the port to connect to at the server host.

The default port for MySQL is 3306.

Pass a path to a Unix socket. This changes the connection stream from TCP to UDS.

By default set to None.

Sets the username to connect as.

Sets the password to connect with.

Sets the database name.

Sets whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.

By default, the SSL mode is Preferred, and the client will first attempt an SSL connection but fallback to a non-SSL connection on failure.

Example
let options = MySqlConnectOptions::new()
    .ssl_mode(MySqlSslMode::Required);

Sets the name of a file containing a list of trusted SSL Certificate Authorities.

Example
let options = MySqlConnectOptions::new()
    .ssl_mode(MySqlSslMode::VerifyCa)
    .ssl_ca("path/to/ca.crt");

Sets PEM encoded list of trusted SSL Certificate Authorities.

Example
let options = MySqlConnectOptions::new()
    .ssl_mode(MySqlSslMode::VerifyCa)
    .ssl_ca_from_pem(vec![]);

Sets the capacity of the connection’s statement cache in a number of stored distinct statements. Caching is handled using LRU, meaning when the amount of queries hits the defined limit, the oldest statement will get dropped.

The default cache capacity is 100 statements.

Sets the character set for the connection.

The default character set is utf8mb4. This is supported from MySQL 5.5.3. If you need to connect to an older version, we recommend you to change this to utf8.

Sets the collation for the connection.

The default collation is derived from the charset. Normally, you should only have to set the charset.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Establish a new database connection with the options specified by self.

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.