pub type MysqlConnection = MysqlLikeConnection<Mysql>;mysql_backend and mysql only.Expand description
A connection to a MySQL database. Connection URLs should be in the form
mysql://[user[:password]@]host/database_name[?unix_socket=socket-path&ssl_mode=SSL_MODE*&ssl_ca=/etc/ssl/certs/ca-certificates.crt&ssl_cert=/etc/ssl/certs/client-cert.crt&ssl_key=/etc/ssl/certs/client-key.crt]
hostcan be an IP address or a hostname. If it is set tolocalhost, a connection will be attempted through the socket at/tmp/mysql.sock. If you want to connect to a local server via TCP (e.g. docker containers), use0.0.0.0or127.0.0.1instead.unix_socketexpects the path to the unix socketssl_caaccepts a path to the system’s certificate rootsssl_certaccepts a path to the client’s certificate filessl_keyaccepts a path to the client’s private key filessl_modeexpects a value defined for MySQL client command option--ssl-modeSee https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode
Errors carry the SQLSTATE the server or client library reports in
DatabaseErrorInformation::sqlstate,
including custom codes raised with
SIGNAL. The server
reports HY000 for errors without a specific SQLSTATE, as described at
https://dev.mysql.com/doc/refman/8.4/en/error-message-elements.html.
§Supported loading model implementations
As MysqlConnection only supports a single loading mode implementation
it is not required to explicitly specify a loading mode
when calling RunQueryDsl::load_iter()
or LoadConnection::load
§DefaultLoadingMode
MysqlConnection only supports a single loading mode, which loads
values row by row from the result set.
use diesel::connection::DefaultLoadingMode;
{
// scope to restrict the lifetime of the iterator
let iter1 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;
for r in iter1 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}
}
// works without specifying the loading mode
let iter2 = users::table.load_iter::<(i32, String), _>(connection)?;
for r in iter2 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}This mode does not support creating multiple iterators using the same connection.
use diesel::connection::DefaultLoadingMode;
let iter1 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;
let iter2 = users::table.load_iter::<(i32, String), DefaultLoadingMode>(connection)?;
for r in iter1 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}
for r in iter2 {
let (id, name) = r?;
println!("Id: {} Name: {}", id, name);
}Aliased Type§
pub struct MysqlConnection { /* private fields */ }