Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error connecting to database with mysqldriver

Tags:

mysql

go

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&...&paramN=valueN] 
like image 746
user3918985 Avatar asked Aug 11 '14 13:08

user3918985


People also ask

Why MySQL database is not connecting?

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.

How do I connect to a MySQL driver?

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.

How do you fix could not connect to MySQL Please check your database settings?

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.


1 Answers

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 
like image 96
VonC Avatar answered Oct 03 '22 22:10

VonC