Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';只有在ECS上才能连接到Golang的RDS mysql_Mysql_Amazon Web Services_Go_Amazon Elastic Beanstalk - Fatal编程技术网

Can';只有在ECS上才能连接到Golang的RDS mysql

Can';只有在ECS上才能连接到Golang的RDS mysql,mysql,amazon-web-services,go,amazon-elastic-beanstalk,Mysql,Amazon Web Services,Go,Amazon Elastic Beanstalk,我尝试在ECS中使用午餐应用程序。 在我当地的docker环境中吃午餐没有问题。 但由于rds连接问题,无法接入ECS中的api服务器。 我在api服务器中使用golang,在db中使用mysql。 我在main.go中调用db.go func main(){ db:=db.NewDatabase(os.Getenv(“MYSQL\u用户”)、os.Getenv(“MYSQL\u密码”)、os.Getenv(“MYSQL\u主机”)) 连接到rds数据库时出错 func NewDatabase

我尝试在ECS中使用午餐应用程序。
在我当地的docker环境中吃午餐没有问题。
但由于rds连接问题,无法接入ECS中的api服务器。

我在api服务器中使用golang,在db中使用mysql。
我在main.go中调用
db.go

func main(){
db:=db.NewDatabase(os.Getenv(“MYSQL\u用户”)、os.Getenv(“MYSQL\u密码”)、os.Getenv(“MYSQL\u主机”))
连接到rds数据库时出错

func NewDatabase(user, password, host string) *Database {
    db, err := sql.Open("mysql", user+":"+password+"@tcp("+host+":3306)/article")
    if err != nil {
        panic(err.Error())
    }

    err = db.Ping()
    // error occurs here
    if err != nil {
        panic(err.Error())
    }
我将其部署到elastic beanstalk。
我检查了环境变量是否设置正确。

以下是完整的源代码:

我希望弹性豆子没有错误。
但实际情况并非如此。
我想知道解决方法。

这是elastic beanstalk中的错误日志

-------------------------------------
/var/log/containers/server-4c66c8d1848a-stdouterr.log
-------------------------------------
panic: dial tcp 172.31.26.91:3306: connect: connection timed out

goroutine 1 [running]:
article/api/db.NewDatabase(0xc00002401b, 0x4, 0xc00002a00f, 0xb, 0xc00002800b, 0x3c, 0xdb94f2)
    /app/db/db.go:20 +0x3bc
main.main()
    /app/main.go:18 +0xee
“连接超时”表示存在防火墙限制,您也可以查看您的mysql白名单,该白名单应该有您ECS的ip