MySQL access denied 1045 error

2019-04-13 01:51发布

问题:

I'm getting a very strange error, I've created a user 'testuser' with the following credentials:

CREATE USER 'testuser'@'%' IDENTIFIED BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'%';
FLUSH PRIVILEGES;

I have also modified my /etc/mysql/my.cnf not to bind to any single address. (Which afaik should accept connections from anywhere?) And restarted mysql.

And I can connect locally no problem.

I am running inside a virtual box on ubunutu.

Trying to connect from my windows machine, gives me MySQL error number 1045 Access denied for user 'testuser'@'192.168.0.22'.

I'm confident that it's not a networking problem as changing the host or port gives a different error "Cannot connect to the specified instance"

Logging in as root and looking at the users table - all looks as expected. (Single row, '%' for host and all permissions set.)

I've been banging my head against the wall all afternoon... can anyone suggest any other possible causes for this error?

Thanks for any help.

回答1:

Run the GRANT statement with the IDENTIFIED BY:

GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'%' IDENTIFIED BY '123456';