Having trouble adding localhost to iptables

Here are my rules:

[[email protected] ~]# iptables -L INPUT --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  localhost            anywhere            tcp dpt:mysql 
2    ACCEPT     tcp  --  blah.members.linode.com  anywhere            tcp dpt:mysql 
3    ACCEPT     tcp  --  blah.net  anywhere            tcp dpt:mysql 
4    DROP       tcp  --  anywhere             anywhere            tcp dpt:mysql 
[[email protected] ~]# 

I can access mysql from home (blah.net) and from my other Linode (blah.members…) with "mysql -u username -ppassword -hx.x.x.x"

But localhost doesn't work…

[[email protected] ~]# mysql -u username -ppassword
ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES)
[[email protected] ~]# 

3 Replies

This is not a result of the connection being blocked by iptables, but rather an authentication failure from MySQL.

In order to log in as [email protected], you need to add a row and the appropriate privileges to the mysql.user table as [email protected], or modify your existing account to [email protected]% (% meaning all hosts) instead of [email protected].

The MySQL manual has more information on how connections are verified: http://dev.mysql.com/doc/refman/5.7/en/ … ccess.html">http://dev.mysql.com/doc/refman/5.7/en/connection-access.html

@jcurry:

This is not a result of the connection being blocked by iptables, but rather an authentication failure from MySQL.

In order to log in as [email protected], you need to add a row and the appropriate privileges to the mysql.user table as [email protected], or modify your existing account to [email protected]% (% meaning all hosts) instead of [email protected].

The MySQL manual has more information on how connections are verified: http://dev.mysql.com/doc/refman/5.7/en/ … ccess.html">http://dev.mysql.com/doc/refman/5.7/en/connection-access.html

Awesome @jcurry that's exactly what I wanted to "rule" out.

Just to add on to jcurry's post, with some builds of mysql, [email protected]% will allow a connection from all external hosts, but will still refuse localhost. You need to explicitly add a row for localhost too.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct