Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Okay, so disclaimer: I'm an absolute mysql noob. Gimme any other development type area and I'm fine.

So, I just started using Ubuntu 12.04 an setup mysql. Never really used localhost since we have a staging environment at work that I usually access. However, a client had a really large DB dump that I needed to access and I didn't want to put in on the server for everyone to deal with so I tried to use localhost

Whenever I try to access it through MySQL Workbench I get an error so I had a look at a couple of articles online and tried a couple of different things but if I run the following command in the terminal, I get an error:

mysql -u root -p -h 127.0.0.1

Produces the following

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

However, if I access mysql like so:

mysql -u root -p

and then enter my password, I can access mysql fine.

Here's what

/etc/mysql/my.cnf

contains at the moment (I've tried looking for other versions of this file). I've left out all the commented out bits for brevity's sake.

[client] 
port            = 3306 
socket          = /var/run/mysqld/mysqld.sock

[mysqld_safe] 
socket          = /var/run/mysqld/mysqld.sock 
nice            = 0

[mysqld]
user            = mysql 
pid-file        = /var/run/mysqld/mysqld.pid 
socket          = /var/run/mysqld/mysqld.sock 
port            = 3306
basedir         = /usr 
datadir         = /var/lib/mysql 
tmpdir          = /tmp 
lc-messages-dir = /usr/share/mysql 
skip-external-locking

key_buffer              = 16M 
max_allowed_packet      = 16M
thread_stack            = 192K 
thread_cache_size       = 8

myisam-recover         = BACKUP

query_cache_limit       = 1M 
query_cache_size        = 16M

log_error = /var/log/mysql/error.log

expire_logs_days        = 10 
max_binlog_size         = 100M

[mysqldump] 
quick quote-names 
max_allowed_packet      = 16M

[mysql]

[isamchk] key_buffer              = 16M

!includedir /etc/mysql/conf.d/
share|improve this question
    
Can you add the full command line of the running mysqld process, and the output of netstat -anp | grep 3306? – Flup Jun 11 '13 at 11:22
up vote 0 down vote accepted

When you log into mysql with

mysql -u root -p

please run this command

SELECT USER(),CURRENT_USER();

USER() reports how you attempted to authenticate in MySQL

CURRENT_USER() reports how you were allowed to authenticate in MySQL

I have discussed this before : how do I see which user I am logged in as in MySQL?

In your case, my guess would be that CURRENT_USER() is 'root'@'localhost'.

There are two things you need to connect to MySQL using 127.0.0.1:

  • You need the user 'root'@'127.0.0.1' defined. That's probably what USER() said.
  • You need to explicit use the TCP/IP protocol

To create the user, login to MySQL and run SHOW GRANTS;

Whatever comes backup, copy and paste it into an editor, replace localhost with 127.0.0.1, command the edited command into mysql and execute it.

Now, to login using TCP/IP do this:

mysql -u root -p -h 127.0.0.1 --protocol=tcp

Once you login, run SELECT USER(),CURRENT_USER(); and you will see something different.

Give it a Try !!!

share|improve this answer
    
Great answer. I'm not sure it's working @ 100% at the moment but I'm sure it will. I just don't have the time to check right now. I will post back. Gave you the up vote because of your detail. Nice!! – Kyle O'Brien Jun 18 '13 at 9:08

check whether mysql server is running, configured firewall allowing mysql server port.check this link also

share|improve this answer

Read this and check your firewall configuration.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .