MySQL access denied 1045 error - mysql

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.

Run the GRANT statement with the IDENTIFIED BY:
GRANT ALL PRIVILEGES ON *.* TO 'testuser'#'%' IDENTIFIED BY '123456';

Related

ERROR 1045 (28000): Access denied for user 'admin'#'localhost' (using password: YES)

I'm trying to log in to mysql via a bash script or to be more specific, I want to check if the passed parameters for the mysql user are thes of an admin user.
For this reason it has to be possible to log in to mysql via a one line command e.g.
mysql -u $dbadmin -p$dbadminpass
To test why I didn't work, I tried it myself on the command line an I'm getting this Error:
ERROR 1045 (28000): Access denied for user 'admin'#'localhost' (using password: YES)
I created the use on #localost and gave all privileges. All my reasarch had no reasults so far.
I checked for any typos
You can try this:
GRANT ALL PRIVILEGES ON *.* TO 'admin'#'%';
FLUSH PRIVILEGES;
or try to connect to 127.0.0.1 not to localhost
This is not a problem with MySQL installation or set-up.
Each account name consists of both a user and host name like 'user_name'#'host_name', even when the host name is not specified. From the MySQL Reference Manual: https://dev.mysql.com/doc/refman/8.0/en/privileges-provided.html#priv_usage
MySQL account names consist of a user name and a host name. This enables creation of accounts for users with the same name who can connect from different hosts.
This also allows MySQL to grant different levels of permissions depending on which host they use to connect.
When updating grants for an account where MySQL doesn't recognize the host portion, it will return an error code 1133 unless if it has a password to identify this account.
Also, MySQL will allow an account name to be specified only by it's user name, but in this case it is treated as 'user_name'#'%'.

Unable to change grant privileges for another user from root user

I'm logged in as root user to an Amazon RDS MySql 5.7 database from MySql workbench.
I've added a user via the following command:
CREATE USER 'my_user'#'%' IDENTIFIED BY 'mypassword';
I'm trying to grant access to the user via this command:
GRANT ALL ON *.* TO 'my_user'#'%'
However, this returns the error:
Error Code: 1045. Access denied for user 'root'#'%' (using password: YES)
I'm not sure if this should work if the user already exists, so based in this post:
https://serverfault.com/questions/115950/how-do-i-change-the-privileges-for-mysql-user-that-is-already-created
I also tried this command:
revoke all privileges on *.* from 'my_user'#'%'
However, I receive the same result. I also had the same problem when I tried creating the user with the GRANT command.
Any help appreciated.
This isn't an answer, but I think the root user might be restricted on RDS. When I did a native install of mysql, the command worked.
None other than RDS user can't have the root user privileges.

Mariadb host works on “localhost” but not IP alternative - 127.0.0.1

I am trying to connect to my database through an ash tunnel using sequel pro but it is not working and forces me to use 127.0.0.1 when entering "localhost" which leads to the problem where if I run on the command line:
mysql --host "localhost"
It works
If I run:
mysql --host "127.0.0.1"
I get the access denied error:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
What is going on?
I have tried:
update user set host='%' where host='localhost'
but this does not work.
Many SQL servers have two or more different user entries for every user that might come in via either localhost or remote. (127.0.0.1 counts as remote).
For example, for the root user, you might have these three user entries.
CREATE USER 'root'#'localhost' IDENTIFIED BY REDACTED;
CREATE USER 'root'#'127.0.0.1' IDENTIFIED BY REDACTED;
CREATE USER 'root'#'%.example.com' IDENTIFIED BY REDACTED;
There's nothing much special about the name root except that it has been granted a lot of privileges when your MySQL was installed. You need to grant the same privileges to the other versions of root#whatever you create.
I created a new user:
CREATE USER 'non-root'#'localhost' IDENTIFIED BY '123';
and then granted them all the same privileges:
GRANT ALL PRIVILEGES ON * . * TO 'non-root'#'localhost';
and then deleted root and renamed non-root to root
and now it finally works.

MySQL connection with DBVisualizer

I've created a user (1caap) in mysql root account and given read only privileges for this user to one of my database. Now my client(1caapuser) is unable to access this database. I've established the connection using Workbench. He's getting the following error when he's trying to access this database using DBVisualizer:
An error occurred while establishing the connection:
Type: java.sql.SQLException Error Code: 1045 SQL State: 28000
Message:
Access denied for user '1caapuser'#'x.x.x.x' (using password: YES)
Please help me out if i'd missed any settings at the earliest.
To resolve this issue you have to grant all privileges on database with identified by the password
Command to run:
GRANT ALL PRIVILEGES ON yourDBname.* TO username#'%' IDENTIFIED BY 'password';
Check the following for more details about the error you get:
http://dev.mysql.com/doc/refman/5.1/en/access-denied.html
https://dev.mysql.com/doc/refman/8.0/en/error-access-denied.html
You must most likely grant proper access for the user at the given IP address/host name. Such as:
grant on . to ''#'';
Check the users guide which specific privileges and what target objects to grant. The important clause above is that you need to specify 'user'#'ip-address'.
Again, check the users guide as there may be a collection of reasons for the error you get.

Unable to connect mysql using ip address

I try to connect my db using host address as my ip address 203.199.209.**,but not able to connect db.if i try to connect my db using host address as localhost it connected successfully.
How to solve this issue?
MySQL grants access based on which host you are connecting from.
Run this command as root:
SELECT user, host FROM mysql.user;
These are the users which exist on your server. Notice the host column.
In short, a user is defined as both a user name (user) and a point of connection (host). When you access your server as localhost, you actually login as some_user#localhost. On the other hand, when you access the sever via its IP address, you actually login as some_user#your.ip.address.here. I guess the latter does not exist on your server.
You may want to create a new user such as some_user#your.ip.address.here or some_user#% (the percent sign is a wildcard; here, it means "any host"):
CREATE USER 'some_user'#'your.ip.address.here' IDENTIFIED BY 'your_password';
GRANT ALL ON your_database.* to 'some_user'#'your.ip.address.here';
If you wish to dig further, see this manual page for more details about MySQL access control, and this page for the CREATE USER syntax.
[edit]
Obviously, as suggested by others, you first need to make sure your server listens to this IP address (203.199.209.**). But if this were not already the case, you should get the following error:
ERROR 2003 (HY000): Can't connect to MySQL server on '203.199.209.**' (111)
The error you are getting definitely indicates a permission issue.
For mysql-5.7.15-winx64 (Windows Version), login as "root" user and run the following queries in MYSQL:
CREATE USER 'user'#'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'localhost' WITH GRANT OPTION;
CREATE USER 'user'#'%' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
and then Re-start your MYSQL DB.
For this version of MYSQL DB no changes are required in "my-default.ini" located in the same location as "bin" folder.