| サンプル集 |
|
■VC ■C# ■Java ■BorlandC ■LinuxC ■MS-DOS ■bash ■Excel VBA ■VBScript ■PHP ■HTML ■perl ■iPhone ■Android ■Lua ■WordPress ■PowerShell ■Python ■Flutter ■Rust ■Node.js ■other |
| Linuxコマンド |
| 用語集 |
| debian メモ |
| apache2 メモ |
| MySQL メモ |
| Oracle メモ |
| PostgreSQL |
| HOME |
mysqlクレートを使ってMySQLへ接続してみます。
◆環境| OS | Windows 10 Home 22H2 64bit |
|---|---|
| rustc | 1.86.0 |
| cargo | 1.86.0 |
Cargo.tomlファイルに依存関係を追記します。
| Cargo.toml | ||
|
MySQLへ接続しバージョン番号を表示するようにしてみます。
| main.rs | ||
|
cargo runで実行したところ正常にMySQLへ接続しバージョン番号を取得できたようです。
> cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.1
9s
Running `target\debug\ymwrust010.exe`
Hello, world!
version=8.0.41
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.1
9sRunning `target\debug\ymwrust010.exe`
Hello, world!
version=8.0.41
MySQLへ接続できない場合、以下のエラーがでました。
> cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.2
0s
Running `target\debug\ymwrust010.exe`
Hello, world!
thread 'main' panicked at src\main.rs:8:32:
called `Result::unwrap()` on an `Err` value: DriverError { Could not
connect to address `localhost:3306': 対象のコンピューターによって拒
否されたため、接続できませんでした。 (os error 10061) }
note: run with `RUST_BACKTRACE=1` environment variable to display a b
acktrace
error: process didn't exit successfully: `target\debug\ymwrust010.exe
` (exit code: 101)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.2
0sRunning `target\debug\ymwrust010.exe`
Hello, world!
thread 'main' panicked at src\main.rs:8:32:
called `Result::unwrap()` on an `Err` value: DriverError { Could not
connect to address `localhost:3306': 対象のコンピューターによって拒
否されたため、接続できませんでした。 (os error 10061) }note: run with `RUST_BACKTRACE=1` environment variable to display a b
acktraceerror: process didn't exit successfully: `target\debug\ymwrust010.exe
` (exit code: 101)期待通りに動きました。
Copyright (C) 2025 ymlib.com
