I'm trying to follow the instructions here https://github.com/go-sql-driver/mysql#installation and http://go-database-sql.org/accessing.html to create a sql.db.
The first line of my code has this
db, err := sql.Open("mysql", "username@localhost/my_db")
When I ran the program on the terminal, I got this:
Default addr for network ''localhost'' unknown
Why is this? When I checked the user and host to mysql it states 'username' and 'localhost'. I followed the parameters like this:
[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
Driver. Connection URL: The connection URL for the mysql database is jdbc:mysql://localhost:3306/sonoo where jdbc is the API, mysql is the database, localhost is the server name on which mysql is running, we may also use IP address, 3306 is the port number and sonoo is the database name.
If you see "Database connection error (2): could not connect to mysql" error message on your site, it generally means that your Joomla configuration. php file has either the wrong database name or the wrong database username. To fix the error you should review your configuration.
You might want to specify the protocol (like 'tcp
'), instead of localhost
directly.
See those examples:
user:password@tcp(localhost:5555)/dbname
In your case:
username@tcp(localhost)/my_db
Note, if you use the default protocol (tcp
) and host (localhost:3306
), this could be rewritten as
user:password@/dbname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With