Struct mysql::OptsBuilder[][src]

pub struct OptsBuilder { /* fields omitted */ }
Expand description

Provides a way to build Opts.

let mut ssl_opts = SslOpts::default();
ssl_opts = ssl_opts.with_pkcs12_path(Some(Path::new("/foo/cert.p12")))
        .with_root_ca_path(Some(Path::new("/foo/root_ca.der")));

// You can create new default builder
let mut builder = OptsBuilder::new();
builder = builder.ip_or_hostname(Some("foo"))
       .db_name(Some("bar"))
       .ssl_opts(Some(ssl_opts));

// Or use existing T: Into<Opts>
let builder = OptsBuilder::from_opts(existing_opts)
       .ip_or_hostname(Some("foo"))
       .db_name(Some("bar"));

Connection URL

Opts also could be constructed using connection URL. See docs on OptsBuilder’s methods for the list of options available via URL.

Example:

let connection_url = "mysql://root:password@localhost:3307/mysql?prefer_socket=false";
let pool = my::Pool::new(connection_url).unwrap();

Implementations

Use a HashMap for creating an OptsBuilder instance:

OptsBuilder::new().from_hash_map(client);

HashMap key,value pairs:

  • user = Username
  • password = Password
  • host = Host name or ip address
  • port = Port, default is 3306
  • socket = Unix socket or pipe name(on windows) defaults to None
  • db_name = Database name (defaults to None).
  • prefer_socket = Prefer socket connection (defaults to true)
  • tcp_keepalive_time_ms = TCP keep alive time for mysql connection (defaults to None)
  • compress = Compression level(defaults to None)
  • tcp_connect_timeout_ms = Tcp connect timeout (defaults to None)
  • stmt_cache_size = Number of prepared statements cached on the client side (per connection)
  • secure_auth = Disable mysql_old_password auth plugin

Login .cnf file parsing lib https://github.com/rjcortese/myloginrs returns a HashMap for client configs

Note: You do not have to use myloginrs lib.

Address of mysql server (defaults to 127.0.0.1). Hostnames should also work.

Note: IPv6 addresses must be given in square brackets, e.g. [::1].

TCP port of mysql server (defaults to 3306).

Socket path on unix or pipe name on windows (defaults to None).

Can be defined using socket connection url parameter.

User (defaults to None).

Password (defaults to None).

Database name (defaults to None).

The timeout for each attempt to read from the server (defaults to None).

Note that named pipe connection will ignore duration’s nanos, and also note that it is an error to pass the zero Duration to this method.

The timeout for each attempt to write to the server (defaults to None).

Note that named pipe connection will ignore duration’s nanos, and also note that it is likely error to pass the zero Duration to this method.

TCP keep alive time for mysql connection (defaults to None). Available as tcp_keepalive_time_ms url parameter.

Can be defined using tcp_keepalive_time_ms connection url parameter.

Set the TCP_NODELAY option for the mysql connection (defaults to true).

Setting this option to false re-enables Nagle’s algorithm, which can cause unusually high latency (~40ms) but may increase maximum throughput. See #132.

Prefer socket connection (defaults to true). Available as prefer_socket url parameter with value true or false.

Will reconnect via socket (on named pipe on windows) after TCP connection to 127.0.0.1 if true.

Will fall back to TCP on error. Use socket option to enforce socket connection.

Can be defined using prefer_socket connection url parameter.

Commands to execute on each new database connection.

Driver will require SSL connection if this option isn’t None (default to None).

Callback to handle requests for local files. These are caused by using LOAD DATA LOCAL INFILE queries. The callback is passed the filename, and a Writeable object to receive the contents of that file. If unset, the default callback will read files relative to the current directory.

Tcp connect timeout (defaults to None). Available as tcp_connect_timeout_ms url parameter.

Can be defined using tcp_connect_timeout_ms connection url parameter.

Bind address for a client (defaults to None).

Use carefully. Will probably make pool unusable because of address already in use errors.

Number of prepared statements cached on the client side (per connection). Defaults to DEFAULT_STMT_CACHE_SIZE.

Can be defined using stmt_cache_size connection url parameter.

Call with None to reset to default.

If not None, then client will ask for compression if server supports it (defaults to None).

Can be defined using compress connection url parameter with values:

  • true - library defined default compression level;
  • fast - library defined fast compression level;
  • best - library defined best compression level;
  • 0, 1, …, 9 - explicitly defined compression level where 0 stands for “no compression”;

Note that compression level defined here will affect only outgoing packets.

Additional client capabilities to set (defaults to empty).

This value will be OR’ed with other client capabilities during connection initialisation.

Note

It is a good way to set something like CLIENT_FOUND_ROWS but you should note that it won’t let you to interfere with capabilities managed by other options (like CLIENT_SSL or CLIENT_COMPRESS). Also note that some capabilities are reserved, pointless or may broke the connection, so this option should be used with caution.

Connect attributes

This value is sent to the server as custom name-value attributes. You can see them from performance_schema tables: session_account_connect_attrs and session_connect_attrs when all of the following conditions are met.

Note

Attribute names that begin with an underscore (_) are not set by application programs because they are reserved for internal use.

The following attributes are sent in addition to ones set by programs.

namevalue
_client_nameThe client library name (rust-mysql-simple)
_client_versionThe client library version
_osThe operation system (target_os cfg feature)
_pidThe client proces ID
_platformThe machine platform (target_arch cfg feature)
program_nameThe first element of std::env::args if program_name isn’t set by programs.

Disables mysql_old_password plugin (defaults to true).

Available via secure_auth connection url parameter.

Trait Implementations

Formats the value using the given formatter. Read more

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

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

Converts self into T using Into<T>. Read more

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Performs the indexed conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Should always be Self

Consumes the current HList and returns an HList with the requested shape. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Attempts to convert self into T using TryInto<T>. 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.