Wings2fly Wings2fly - 13 days ago 9
MySQL Question

Unable to connect MySQL using 'root'@'IP_Address' in Vagrant

I am trying to connect

Vagrant VM
I can access
in vagrant ssh , but when I connect using
which is the IP used for Vagrant VM, I am getting
access denied

This is my Vagrant file settings:

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine. "forwarded_port", guest: 80, host: 8080 "forwarded_port", guest: 3306, host: 3306

# Create a private network, which allows host-only access to the machine
# using a specific IP. "private_network", ip: ""

root@ is already added in mySQL, and permissions are given

mysql> select User,Host from mysql.user;
| User | Host |
| root | |
| mysql.sys | localhost |
| root | localhost |
3 rows in set (0.00 sec)

MySQL 5.7 mysqld.cnf

I have tried bind-address to '' and bind-address ''.

Still error message shows:

vagrant@vagrant-ubuntu-trusty:/etc/mysql/mysql.conf.d$ mysql -u root@ -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root@'@'localhost' (using password: YES)


Look carefully at the error message. The error message is indicating that the username supplied to the MySQL server is:


And the host that MySQL is seeing the connection from is:


Here's how the MySQL client is interpreting these options:

 mysql -u root@ -p

-u user supplies a string value, in this case, it's seeing 'root@' as the username value. The @ sign and the digits and dots are just part of the username string. There's no no special meaning given to those characters, it's just a string. And MySQL server is going to look for a row in the mysql.users table that has User value that matches that string. (

To find a match, MySQL is also going to look at the value in the Host column. That is going to have to match the host the connection is seen as coming from. What that means is 'root'@'localhost' is a different user than 'root'@''.

-p prompt for password

Omitted are any command options for the protocol to use, the host to connect to, the port number, etc. MySQL default when we don't supply any of that is

-h localhost

as if that is what we had specified.

If we want to connect to the MySQL server via the TCP/IP protocol, and not using a Unix socket, we need to specify -h hostname or -h ipaddress, or specify --protocol=TCP

The hostname "localhost: has a special meaning in MySQL. That's a connection through a Unix socket, not through the loopback IP address we might expect.

For example, to connect to the MySQL server on the local machine, listening on the default port 3306, using the loopback IP address:

  mysql -h -u root -p

Most of this information is covered pretty well in the MySQL Reference Manual.

Also, by default, MySQL uses reverse DNS lookup to resolve IP addresses to hostnames.

If we want to use IP addresses in the Host column of the mysql.users table, we need to disable reverse DNS lookup. We do that by including this option:


In the my.cnf configuration file.