25

I have installed Mysql 5.1 on Mac OS X 10.7 Lion. For some reason, though, when I try starting the server with the command "mysqld" I get an error in the log file which says:

120328 21:32:40 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use

120328 21:32:40 [ERROR] Do you already have another mysqld server running on port: 3306 ?

120328 21:32:40 [ERROR] Aborting

If I run "netstat -nat | grep 3306" in my terminal, I get the following:
tcp4 0 0 *.3306 . LISTEN

UPDATE:

So here's the output for that.
mysqld 24645 sb1752 12u IPv4 0xffffff8010f6bde0 0t0 TCP *:mysql (LISTEN)

This is odd though! Because my mysql server is not started.
When I type "mysql" in command line, it says
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I did install other version of mysql and uninstalled earlier today. Any idea what to do here?

Shaan
  • 803
  • 2
  • 11
  • 24

2 Answers2

37

use lsof -i TCP:3306 to check which program binds port 3306

dhchen
  • 1,118
  • 2
  • 9
  • 23
  • this is a nice way as it will also catch any tunnels and whatnot you might have setup. I use scp over tunnels and had bound a tunnel on 3306 – qrikko May 27 '15 at 07:47
  • In my case, this answer gave me the way for solving this error. I check a mysqld process is running at that port, and I killed. Then, I could start mysql with restarting mysql server via brew(I guess there was an error on starting mysql server in the two ways: mysql.server and brew services). – KoreanXcodeWorker Oct 03 '18 at 23:54
  • had to add sudo to get it working sudo lsof -i TCP:3306 then sudo kill [pidid] – Abdullah Tahan Oct 01 '19 at 23:59
  • Perfect, ran your command and used answer above to kill the serivce – Josh Bonnick Oct 23 '20 at 12:56
20

You could use netstat -lp | grep 3306 to find out what program is already listening on port 3306 (you should see PID/Program name in last column) and stop that (maybe mysql is already running?).

Alternatively you could start the newly installed server on a different port. (edit my.cnf and change the default port there)

stewe
  • 39,054
  • 13
  • 75
  • 73