用go语言实现192.168.13.11的mysql服务中查询hyap数据库中的hy_fifthbaseapp_location_table内容
时间: 2023-05-24 17:01:41 浏览: 64
以下是用 Go 语言实现在 192.168.13.11 上的 MySQL 服务中查询 hyap 数据库中的 hy_fifthbaseapp_location_table 内容的代码示例:
```
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// Open a connection to the MySQL server
db, err := sql.Open("mysql", "username:password@tcp(192.168.13.11:3306)/hyap")
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
// Query the hy_fifthbaseapp_location_table table and print the results
rows, err := db.Query("SELECT * FROM hy_fifthbaseapp_location_table")
if err != nil {
fmt.Println(err)
return
}
defer rows.Close()
for rows.Next() {
var id int
var name string
var location string
err = rows.Scan(&id, &name, &location)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("id: %d, name: %s, location: %s\n", id, name, location)
}
}
```
请将上面的 "username" 和 "password" 替换为实际的用户名和密码,以便连接到 MySQL 服务器。注意,这是一段简单的示例代码,您需要根据实际情况对其进行适当的更改或扩展。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)