Connection failed: Access denied for user - mysql

I am trying to access database on remote server with normal user (testuser) with no GRANT privileges. When I try to access the database using the above user I get the following error:
Access denied for user 'testuser'#'%' to database 'test_db'
I do not have any database interface to directly grant privileges to this user. I have SSH root access to the server. How do I grant privileges to this user?

Login to mysql command line interface with your root user. Run the below commands to give access
GRANT ALL PRIVILEGES ON *.* TO 'testuser'#'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Related

How i can give all privilages for a user to all databases in my shared hosting

I have a user and 10 databases in my cpanel and i want grant this user to all databases in my host using sql command.
I used this command :
grant all privileges on *.* to 'myacc_myuser'#localhost identified by 'mypass' with grant option;
But it give me this error :
#1045 - Access denied for user 'myacc'#'localhost'
How i can resolve this problem ?
Thanks.

Error 1045 MySQL

I have a remote database which I connect through a sql management with a user and its password. The database has four tables and a view. To put the permissions I have executed the following command:
mysql> grant all privileges on databasename.* to 'username'#'%' identified by 'password' with grant option;
Then, all it's ok. When I connect to the database, I can see the data from the tables but if I explore the view, for example:
select * from viewname;
I get this error:
Error SQL (1045): Access denied for user 'username'#'%' (using password: YES)
I don't know what is the problem, because the rest of the database is OK.
Once you have given the desired privileges for your user, you will need to run this command within the MySQL command prompt:
Flush the privileges with this MySQL command: FLUSH PRIVILEGES;

Allow GRANT permission to MySQL User

I am creating a user app_root identified by a password with limited permission. This user should only be able to create a database with prefix, create a new user, and grant permission to new user to access the database. So this is what I am doing.
CREATE USER app_root#localhost IDENTIFIED BY 'password';
GRANT CREATE USER ON *.* TO app_root#localhost WITH GRANT OPTION;
GRANT CREATE ON `myapp\_%`.* TO app_root#localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;
The user is duly created. Now I log in to mysql with app_root user and execute following:
CREATE DATABASE test;
It fails as expected because name of database does not contain myapp_ prefix.
CREATE DATABASE myapp_test;
CREATE USER myapp_test#localhost IDENTIFIED BY 'ABC';
Both database and user are successfully created. But if I execute grant statement, error occurs.
GRANT ALL PRIVILEGES ON myapp_test.* TO myapp_test#localhost;
It generates ERROR 1044 (42000): Access denied for user 'app_root'#'localhost' to database 'myapp_test'. Could anyone please tell me what is wrong with my approach?
MySQL Version - Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)
Edit - As suggested, I granted all privileges to app_root user. But it still does not change anything.
GRANT ALL ON `myapp\_%`.* TO app_root#localhost WITH GRANT OPTION;
FLUSH PRIVILEGES;

Access denied for mysql user

I get this error when I try to access my database via the user 'spot'#'localhost' identified by its password.
PermissionsError: (1045, "Access denied for user 'spot'#'localhost' (using password: YES)", None)
I create this user using these two lines:
create user 'spot'#'localhost' identified by 'fakepasswd';
grant all privileges on *.* to 'spot'#'localhost';
When I run this code locally, it works fine. When I run this code on a different machine, I get the aforementioned error.
Yet when I run show grants for 'spot'#'localhost' on both machines, they both give me the same output:
GRANT ALL PRIVILEGES ON *.* TO 'spot'#'localhost' IDENTIFIED BY PASSWORD '*196BDEDE2AE4FRO4CA44C47D54D78478C7E2BD7B7'
How can I debug this access problem?
Yo need to grant privileges not only from localhost, run this querys:
create user 'spot'#'%' identified by 'fakepasswd';
grant all privileges on *.* to 'spot'#'%';
flush privileges;
This allow the user to connect from ANY ip, you can replace the % with the ip of your server.

java.sql.SQLException: Access denied for user

I want to create an user that can access from any hosts to Mysql server
I use
create user abc#10.10.131.17 identified by 'abc123'
and
grant all privileges mydb.* to 'abc'#'%';
But when i run client,the error occurs:
"java.sql.SQLException: Access denied for user 'abc'#'10.10.0.7' (using password: YES)
help me,please!
One obvious guess would be that you didn't do FLUSH PRIVILEGES; after issuing GRANT statement.
Another obvious guess (not sure if typo in the question) is that syntax of GRANT is GRANT ALL PRIVILEGES ON mydb.* TO 'abc'#'%';, with ON in it.
You have created an user with allowing IP 10.10.131.17 and you are trying to connect MySQL Server from IP 10.10.10.7. So it won't work.
To access MySQL Server you have to create user allowing IP 10.10.10.7 or allowing all IPs using %.
CREATE USER `abc`#`10.10.10.7` IDENTIFIED BY 'abc123'
GRANT ALL PRIVILEGES mydb.* TO `abc`#`10.10.10.7`;
OR
CREATE USER `abc`#`%` IDENTIFIED BY 'abc123'
GRANT ALL PRIVILEGES mydb.* TO `abc`#`%`;