This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

I am trying to connect MySQL using Vagrant VM.
I can access MySQL using root@localhost in vagrant ssh , but when I connect using root@192.168.33.10 which is the IP used for Vagrant VM, I am getting access denied error.

i think you set a password when your sql connection doesn't need a password
– Chrys UgwuOct 14 '16 at 4:00

I'm not much knowledgeable about vagrant, but are you trying to access mysql from inside the VM or from the host or another computer? I'm guessing locally, so try creating another user and connecting with it instead of root, or Grant access to this IP to root GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.33.10' IDENTIFIED BY 'P4$$WORD' WITH GRANT OPTION;
– Martins.AOct 14 '16 at 4:10

2 Answers
2

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

'user@192.168.33.10'

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

'localhost'

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

mysql -u root@192.168.33.10 -p

-u user supplies a string value, in this case, it's seeing 'root@192.168.33.10' 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'@'192.168.33.10'.

-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 127.0.0.1 -u root -p

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