Possible http server socket and Apache2 MySql conflict

I am new to go and trying to get the http server to do what I want it to do. I have frequently triggered a possible server socket conflict that I can only resolve locally by a reboot. Online requires installing a backup :frowning:


// web-page error:

A PHP Error was encountered

Severity: Warning
Message:  mysqli_connect(): (HY000/2002): Connection refused

// MySql error log:

160130  1:31:34 [ERROR] Can't create IP socket: File exists
160130  1:31:34 [ERROR] Can't start server: cannot resolve hostname!
160130  1:31:34 [ERROR] Aborting

// go script

func main() {
    http.HandleFunc("/", handler)
    err := http.ListenAndServe(":8080", nil)

    if err != nil {

As mentioned locally it has happened frequently and I would like to know if it is possible to prevent this MySql error or at least a Kludge to prevent a reboot or another backup installation :frowning:

Added actual web-page error message.

You have another web server running there (something that’s not Go is serving PHP), and potentially another MySQL instance.



You have another web server running there (something that’s not Go is serving PHP), and potentially another MySQL instance.

I don’t know why the other web-server conflicted. It had never previously happend until I tried to run the Golang server alongside Apache.

If or when this does happen again, can you explain how to recover and to reload MySql. Php was working OK.

When MySql refused to load I searched extensively. Numerous solutions were tried and only able to resolve the problem by installing a backup.

I am surprised others have not had similar experiences.

If the Go code you showed us in your first post is your entire Go application, then it has nothing to do with the MySQL error.

You might be able to figure out what happened to MySQL by looking at the log files, but it’s not related to Go from what we can see here.

My bet is that Apache is running port 80, and you forgot to visit your Go website on :8080 (the :8080 tells the server which port you want to connect to)

1 Like

Use netstat -l to see active servers and ports to avoid possible conflicts :wink:

1 Like

Many thanks for your reply.

Unfortunately using ports is new to me and I don’t know where to start looking or how to interpret the information :frowning:

Many thanks for your reply.

I tried netstat - 1 and did not know how to interpret the information :frowning:

I have since learnt that if this message appears after trying to compile the Golang script:

2016/02/06 11:13:12 listen tcp :8080: bind: address already in use

The problem is resolved by the following:

lsof -ti:8080 | xargs kill -9

Following finds whatever is using port 8080

lsof -ti:8080

The things are quite simple. You use in your program a port (let say 8080) to listen requests sent to your program. Also, other programs hosted on that machine listen other ports. Maybe other program listen the same port like you and result a conflict. With netstat (the top part of the result) you ca see who and what listen and this can help you to change ports properly.

tip: also try netstat -l | grep :

note that is netstat -l (from listen) not netstat - 1


Many thanks for your reply.

I have very little experience with Apache2 ports. Biggest problem is not knowing the magic search words to find and understand the proposed solutions.

I have found and used the following command numerous times to free the locked port:8080.

lsof -ti:8080 | xargs kill -9

Yep, the solution is not killing the process but stopping the service who already listen 8080 or configure Apache or whatever to listen other port than 8080. Otherwise simply move your go service to other port.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.