I am trying to create a simple API using Rust, MySQL and Diesel on a Windows 10 64bit machine. I am unable to connect to MySQL. I have tried different approaches. If I do a simple connection then it works but if I use diesel it gives SSL error. The below code works. It does connect to MySQL Database.
use mysql::*;
use mysql::prelude::*;
...
...
let url = "mysql://myusr:mypass@localhost:3306/pubdb";
let pool = Pool::new(url)?;
let mut conn = pool.get_conn()?;
...
I setup diesel cli using below command:
cargo install diesel_cli --no-default-features --features mysql
It's always hard do say what's wrong with such connection issues as that's mostly dependent on your environment. The error message indicates that your database server might need a ssl connection. Have you tried to set the relevant parameters in the connection url? Does your libmysqlclient version include ssl support?
Thanks for your reply. I investigated further. It runs if I specify the ssl_mode=DISABLED in the command line but unable to get it working using .env file, i.e. via rust code. See below:
Tried giving DATABASE_URL in double quotes. Still got an error.
DATABASE_URL="mysql://myusr:mypass@localhost/pubdb?ssl_mode=DISABLED"
D:\Rust\diesel_demo>diesel database setup
The --database-url argument must be passed, or the DATABASE_URL environment variable must be set.
Let me know if anyone has any suggestions on how to specify this in .env file. The documentation says default for ssl_mode is PREFERRED. If we can change it to DISABLED, that might be another solution.