Can't run; don't know why?

Post your code, please. And don't post it in image.

I think it might be something wrong with your mysql URL.

Looks like you had incorrectly used the mysql crate. Please look for its parameters in your code (or any configuration files, if you're using e.g. diesel).

Cargo.toml
[dependencies]
mysql = "16.1.0"


use mysql;
fn main() {
conn_mysql();
}
struct Dept {
deptno: i32,
dname: String,
loc: String,
}
fn conn_mysql() {
let pool = mysql::Pool::new("mysql://localhost:3306/mldn8003?useUnicode=true&characterEncoding=utf-8&serverTimezone=CTT").unwrap();
let depts: Vec = pool
.prep_exec("SELECT deptno,dname,loc FROM dept", ())
.map(|result| {
result
.map(|x| x.unwrap())
.map(|row| {
let (deptno, dname, loc) = mysql::from_row(row);
Dept {
deptno: deptno,
dname: dname,
loc: loc,
}
})
.collect()
})
.unwrap();
for dept in depts {
// let deptno: i32 = dept.deptno;
// let dname: String = dept.dname;
// let loc: String = dept.loc;
// println!("部门编号:{},部门名称:{},部门职能{}", deptno, dname, loc);
println!(
"部门编号:{:?},部门名称:{:?},部门职能{:?}",
dept.deptno, dept.dname, dept.loc
);
}
println!("Yay!");
}

Surrounding your code which in this post with a code block syntax.


Try:

let pool = mysql::Pool::new("mysql://localhost:3306/mldn8003?useUnicode=yes&characterEncoding=utf-8&serverTimezone=CTT").unwrap();

Or:

let pool = mysql::Pool::new("mysql://localhost:3306/mldn8003?characterEncoding=utf-8&serverTimezone=CTT").unwrap();

Thank you for your advice. I'm a beginner. How to surround me?

```rust
// your code here
```

Please write a pseudo code to show me

Hello! Where is my code wrong?

你好像没明白我在说什么,我意思是请把你这个 post 里的代码放到 markdown 的代码块里。

另外你的错误是 URL 参数错误,我已经给出了两个建议,你自己尝试修改。

fn conn_mysql() {
//定义连接字符串
// let pool = mysql::Pool::new("mysql://localhost:3306/mldn8003?useUnicode=true&characterEncoding=utf-8&serverTimezone=CTT").unwrap();
let pool = mysql::Pool::new("mysql://localhost:3306/mldn8003").unwrap();
//查询数据库
let depts: Vec = pool
.prep_exec("SELECT deptno,dname,loc FROM dept", ())
.map(|result| {
result
.map(|x| x.unwrap())
.map(|row| {
let (deptno, dname, loc) = mysql::from_row(row);
Dept {
deptno: deptno,
dname: dname,
loc: loc,
}
})
.collect()
})
.unwrap();
for dept in depts {
// let deptno: i32 = dept.deptno;
// let dname: String = dept.dname;
// let loc: String = dept.loc;
// println!("部门编号:{},部门名称:{},部门职能{}", deptno, dname, loc);
println!(
"部门编号:{:?},部门名称:{:?},部门职能{:?}",
dept.deptno, dept.dname, dept.loc
);
}
println!("Yay!");
}

Try to read the error output yourself. Access Denied, Password Missing.

拒绝访问,你没有提供数据库的密码。

Thanks to the teacher for your careful guidance? thank you very much!!!