4

My database link is a domain name instead of an IP address, and I don't use the ip address. Below is my configuration.

orm.RegisterDataBase("default", "mysql", "root:root@*******.aliyuncs.com:3308/dbname?charset=utf8")

Error Message:

register db Ping default, default addr for network '***.mysql.rds.aliyuncs.com:3308' unknown must have one register DataBase alias named default

1 Answer 1

10

I checked on the go-mysql-driver source code, on file dsn.go:116, the error only occurs when the network type is "".

You might need to specify the selected network type on the connection string (whether it is tcp or unix). Use the below connection string scheme instead of the one you are using.

<username>:<password>@<network-type>(<host>:<port>)/<dbname>

With your code, it would be like this:

connectionString := "root:root@tcp(*******.aliyuncs.com:3308)/dbname"
orm.RegisterDataBase("default", "mysql", connectionString)

Note: network type tcp is chosen in the example above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.