Expand description

Read and parse MySQL’s .mylogin.cnf file.


Add myloginrs to Cargo.toml:

myloginrs = "0.1"


To get a HashMap of login info for "client" just use the parse function:

let file_path = PathBuf::from(

let client_info = myloginrs::parse("client", Some(&file_path));

Then you can use that HashMap with an OptsBuilder or other structs from the mysql:

let opts = OptsBuilder::new()
    .tcp_port(u16::from_str_radix(&client_info["port"], 10)?)

let _conn = Conn::new(opts);

Starting with mysql 20.1.0, you can do the even simpler:

let opts = OptsBuilder::new().from_hash_map(&client_info).unwrap();
let _conn = Conn::new(opts);

If you would rather get a String that contains the whole file, use read:

let mylogin_plaintext = myloginrs::read(None);

println!("{}", mylogin_plaintext);

This second example passes None as the path to use the default .mylogin.cnf location (%APPDATA%\MySQL\.mylogin.cnf on windows or ~/.mylogin.cnf on everything else).


Parse the file at path, decrypting it and return a HashMap containing the key value pairs for the login_path heading.

Read the file at path and decrypt it. Return the contents as a String.