I am guessing I am forgetting something obvious, but I can't seem to connect to 127.0.0.1 using MySQL. Connecting via localhost works.
MySQL / Linux version: Server version: 10.0.31-MariaDB-0ubuntu0.16.04.2 Ubuntu 16.04
This works:
$ mysql -h localhost -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 71982
Server version: 10.0.31-MariaDB-0ubuntu0.16.04.2 Ubuntu 16.04
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
This does not work:
$ mysql -h 127.0.0.1 -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
It seems to me that MySQL is listening to 127.0.0.1:3306:
$ netstat -plnt
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1841/mysqld
I can even connect to port 3306 using Telnet:
$ telnet 127.0.0.1 3306
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
j
5.5.5-10.0.31-MariaDB-0ubuntu0.16.04.2TGYk-=,d5-??wz}'Hr*s+u24mysql_native_password
Just in case, I have also created a user with grant option for host 127.0.0.1:
mysql > CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '<redacted>';
mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;
Here is some information about users (query suggested by @brian-ecker):
MariaDB [(none)]> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-------------+
| User | Host | plugin |
+------------------+-----------+-------------+
| root | localhost | unix_socket |
| root | 127.0.0.1 | |
+------------------+-----------+-------------+
I have also tried creating a root user that is identified by unix_socket without it helping:
MariaDB [(none)]> CREATE USER 'root'@'127.0.0.1' IDENTIFIED VIA unix_socket;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;
MariaDB [(none)]> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-------------+
| User | Host | plugin |
+------------------+-----------+-------------+
| root | localhost | unix_socket |
| root | 127.0.0.1 | unix_socket |
+------------------+-----------+-------------+
Do you have any suggestions as to why I can connect via "localhost" but not "127.0.0.1"?