After executing the following mysql statement to create database and giving privileges to user can't access mysql
create database my_db;
GRANT ALL PRIVILEGES ON my_db.* TO 'user'#'%' IDENTIFIED BY 'mypasswd';
GRANT SELECT ON my_db.* TO 'user'#'%' IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;
mysql -u user -p mypasswd drops me
Access denied for user 'user'#'localhost'
You need to give privileges separately for user to connect from localhost. % will not work.
`GRANT ALL PRIVILEGES ON my_db.* TO 'user'#'localhost' IDENTIFIED BY 'mypasswd';
GRANT SELECT ON my_db.* TO 'user'#'localhost' IDENTIFIED BY 'mypasswd';`
There is no space between -p and your password.
As you granted rights only for the database my_db, add the db also to connect directly to it.
mysql -u user -pmypasswd my_db
I tried this:
GRANT ALL ON my_db.* TO 'user'#'%' IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;
And afterwards
./mysql -uuser -pmypasswd
worked ok for me.
If it doesn't, try with localhost:
GRANT ALL ON my_db.* TO 'user'#'localhost' IDENTIFIED BY 'mypasswd';
FLUSH PRIVILEGES;
Related
How to grant all privileges to all users in mySQL ?
GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'#'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
What do I replace username with in order to allow it for every user on the given IP?Even if it is '' i.e no username at all in input ?
I tried * and % in username but that did not help.
You can try like this:
GRANT ALL PRIVILEGES ON *.* TO ''#'localhost' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
The manual says:
In this case, any user who connects from the local host with the
correct password for the anonymous user will be permitted access, with
the privileges associated with the anonymous-user account.
This is working for all my MySQL users irrespective of their hostname and Ips.
GRANT ALL ON <yourdbname>.* TO ''#'%' IDENTIFIED BY 'yourdbpassword';
FLUSH PRIVILEGES;
This should work:
GRANT ALL PRIVILEGES ON 'database'.'table' TO '%'#'1.2.3.4' WITH GRANT OPTION;
Wild card does not work for user in mysql grant privilege command.
If you know list of users then yOU can try :-
GRANT ALL PRIVILEGES ON *.* TO 'user1'#'1.2.3.4',
'user2'#'1.2.3.4',
'user3'#'1.2.3.4',
'user4'#'1.2.3.4',
'user5'#'1.2.3.4',
'user6'#'1.2.3.4';
If you want to grant all privileges to all users and be able to use without a password, the command:
GRANT ALL PRIVILEGES ON *.* TO ''#'%' IDENTIFIED BY '' WITH GRANT OPTION;
If, for example you hava database named 'my_db' and you doing operations from localhost, the command can be the follow:
GRANT ALL PRIVILEGES ON my_db.* TO ''#'localhsot' IDENTIFIED BY '' WITH GRANT OPTION;
MySQL does not support wildcards in user names, so you cannot do that in a single grant.
see the official doc
I am trying to run
GRANT ALL PRIVILEGES ON * . * TO 'root'#'localhost';
from a remote server to localhost/phpmyadmin but getting ERROR 1045 (28000): Access denied for user 'root'#'%' (using password: NO).
mysql> show grants;
+----------------------------------+
| Grants for root#% |
+----------------------------------+
| GRANT USAGE ON *.* TO 'root'#'%' |
+----------------------------------+
How can I resolve this problem? I have gone through a lot of suggestions over internet but can't actually figure out.
I think, you forgot to flush privileges.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' with GRANT OPTION;
mysql> FLUSH PRIVILEGES;
Note:
I have included with GRANT OPTION because as doc says:
The GRANT OPTION privilege enables you to give to other users or remove from other users those privileges that you yourself possess.
Edit 1:
Depending on comments, seems like you have forgotten the root password. So try to reset like this:
Stop the MySQL Server.
sudo /etc/init.d/mysql stop
Start the mysql without password
sudo mysqld_safe --skip-grant-tables &
Login to mysql as root:
mysql -u root
Set new password to root
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
Flush privileges.
FLUSH PRIVILEGES;
Finally, restart mysql normally.
If you have root credential , then Set the privileges like mentioned below.
grant all privileges on db.* to user#'%' identified by 'pass';
Thanks
I have created user and grant all permissions, but still not able to connect to the sql using it. Could someone kindly help resolving this?
Steps followed
mysql --user=root mysql;
CREATE USER 'db_user'#'%' IDENTIFIED BY 'password';
CREATE USER 'db_user'#'localhost' IDENTIFIED BY 'password';
CREATE USER 'db_user'#'hostname' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'hostname' WITH GRANT OPTION;
When I try to connect like
mysql -u db_user -ppassword -h 'hostname'
I get this error
ERROR 1045 (28000): Access denied for user 'db_user'#'hostname' (using password: YES)
MariaDB [(none)]> show grants for db_user#'hostname';
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'hostname' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION
1 row in set (0.00 sec)
What is it missing that it is not letting to connect?
Can you confirm again that the hostname is the hostname of the local host?
Can you try these.
DROP USER 'db_user'#'localhost';
DROP USER 'db_user'#'%';
DROP USER 'db_user'#'hostname';
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'%' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'db_user'#'hostname' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' WITH GRANT OPTION;
mysql -u db_user -ppassword -h `hostname`
I type the commands below:
mysql –u root -p
Grant all privileges on *.* to root#”%” identified by “rootpassword” with grant option;
Grant all privileges on mysitedb.* to root#localhost;
then the server crashed:
Could not establish database connection. Please check the username,
password and hostname in the config file, and if necessary set up the
appropriate MySQL user and privileges.
change the grand statement in to below one, then solved:
mysql –u root -p
Grant all privileges on *.* to root#”%” identified by “rootpassword” with grant option;
Grant all privileges on mysitedb.* to root#localhost identified by “rootpassword” with grant option;
I have installed wampserver. i revoke the the delete privilege from root user. now i want to grant same privilege back to root user but it gives the error:
i tried the following command
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
but the command gives the
#1045 - Access denied for user 'root'#'localhost' (using password: YES)
there are two root users
root localhost
root 127.0.0.1
root localhost do not have DELETE privilege. root 127.0.0.1 have all privileges. i tried with http://127.0.0.1/phpmyadmin but the same error occurs. is there a way to reset root user privileges.
I have had issues with GRANT ... TO 'user'#'%' ... before. Try to additionally issue the following GRANT statement:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
For me, this did the trick. Somehow mysql seems picky when it comes to localhost