I am trying to connect
# 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.
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3306, host: 3306
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.10"
mysql> select User,Host from mysql.user;
| User | Host |
| root | 192.168.33.10 |
| mysql.sys | localhost |
| root | localhost |
3 rows in set (0.00 sec)
I have tried bind-address to '0.0.0.0' and bind-address '192.168.33.10'.
vagrant@vagrant-ubuntu-trusty:/etc/mysql/mysql.conf.d$ mysql -u email@example.com -p
ERROR 1045 (28000): Access denied for user 'firstname.lastname@example.org'@'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 email@example.com -p
-u user supplies a string value, in this case, it's seeing
'firstname.lastname@example.org' 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
-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
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
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 127.0.0.1 -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:
my.cnf configuration file.