I'm working on a MySQL server I haven't configured my self and I'm a bit of a noob when it comes to SQL.
I've created a database like this:
root#localhost:~# mysqladmin -u root -p create drupal
And then tried to grant privileges like this:
root#localhost:~# mysql -u root -p
MariaDB [(none)]> GRANT ALL PRIVILEGES ON drupal.* TO root IDENTIFIED BY ...;
But get this error:
ERROR 1044 (42000): Access denied for user 'root'#'localhost' to database 'drupal'
[Update] I get this error with all forms of GRANT commands.
But according to SHOW GRANTS I should have privileges:
MariaDB [(none)]> SHOW GRANTS;
+---------------------------------------------------------------------------
-------------------------------------------+
| Grants for root#localhost
|
+---------------------------------------------------------------------------
------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD
'*...' |
+---------------------------------------------------------------------------
-------------------------------------------+
1 row in set (0.00 sec)
MySQL version is: mysql Ver 15.1 Distrib 10.1.26-MariaDB
On Debian 9.5
The problem was that the root user didn't have Grant privileges.
SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
I fixed it with this command:
UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'#'localhost';
You have to log out and in again for it to work.
Related
I'm trying to install MySQL to my computer, and I am following these steps.
After I install and start MySQL, I Go back to Terminal and type:
sudo /usr/local/mysql/bin/mysql -u root -p
Terminal asks me to type my password, then I type my Mac PW, and then I get this error:
Access denied for user 'root'#'localhost' (using password: YES)
I apologize in advance, I am a beginner and have NO idea what to do next. I've done some research online and can't quite figure it out.
here's a link to the steps I'm following. I am stuck on Install MySQL # 9:
https://websitebeaver.com/set-up-localhost-on-macos-high-sierra-apache-mysql-and-php-7-with-sslhttps
Check your Grants
mysql> show grants;
+----------------------------------------------------------------------------------------------------------+
| Grants for root#localhost |
+----------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------+
2 rows in set (0.07 sec)
if no set then set them with:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION;
I am connected as a root user in MySql.
Root user has GRANT and
grant all privileges on *.* to 'root'#'localhost' with grant option;
went through last time I did it without error code returned.
When I however change root to sqluser there is: "Error Code: 1410. You are not allowed to create a user with GRANT
"
Earlier action:
grant grant option on *.* to 'sqluser'#'%'
and it didn't return error code. However as I ran query with localhost there is error code with number 1410.
I have MySql 8.0 installed.
How can I make grant all privileges go through?
I had the same problem when setting up a new mysql database, at the point of adding the first user.
I have found my problem was resolved by removing the #'localhost' from the GRANT.
This works:
mysql> grant all privileges on *.* to 'laravel_user';
Query OK, 0 rows affected (0.10 sec)
This does not:
mysql> grant all privileges on *.* to 'laravel_user'#'localhost';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql version:
$ mysql -V
mysql Ver 8.0.12 for osx10.14 on x86_64 (Homebrew)
I was following this guide to set up the database:
https://www.a2hosting.co.uk/kb/developer-corner/mysql/managing-mysql-databases-and-users-from-the-command-line
test this code.
GRANT ALL PRIVILEGES ON *.* TO 'user'#'localhost' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
I want to create new DB in mysql.
I am logged in as root. I have set password for root user.
mysql> SHOW GRANTS FOR root;
+---------------------------------------------------------------------------------------------+
| Grants for root#% |
+---------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY PASSWORD <secret> WITH GRANT OPTION |
| GRANT PROXY ON ''#'' TO 'root'#'%' WITH GRANT OPTION
|
+---------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> create database xxx;
ERROR 1044 (42000): Access denied for user 'root'#'localhost' to database 'xxx'
One thing I notice that i do not have mysql db
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| info_schema |
| sms_auto |
| smstest |
+--------------------+
Please can you help me
Make sure you set your user privileges right
Like -host localhost -user root and -pass {your pass word}
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' IDENTIFIED BY PASSWORD;. Set a user privilege to a particular user like people and then follow the example grant all on people.*to 'root'#'localhost' identified by 'PASSWORD';
I have started MySQL in safe mode then assigned appropriate privileges( Referenced from here)
Stop MySQL service
Run mysqld_safe --skip-grant-tables &
Type MySQL -u root -p and press enter.
Enter your password
At the MySQL command line enter: use mysql;
After this, I have updated the privileges in mysql.user table for appropriate host and user. Flush privileges;
Now this works for me
you can also refer the answer for update privilages
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 create a MySQL user as follows:
mysql> grant all privileges on *.* to mysql#'%' IDENTIFIED by 'myPassword' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> exit;
Bye
Then I try to login with that newly created user but it doesn't work.
% mysql -u mysql -pmyPassword
ERROR 1045 (28000): Access denied for user 'mysql'#'localhost' (using password: YES)
%
Why?
I believe localhost is special and not covered by the '%'.
Issue
mysql> grant all privileges on *.* to mysql#'localhost' IDENTIFIED by 'myPassword' with grant option;
and it should work
It seems counter-intuitive, but 'localhost' is not matched by '%' in MySQL. The reason is that all '%' matches all TCP/IP connections, but connections from 'localhost' are mapped to the unix domain socket.
There are two possible solutions:
Do an extra grant for the user at 'localhost':
mysql> grant all privileges on *.* to mysql#'localhost' IDENTIFIED by 'myPassword' with grant option;
PS: you don't have to FLUSH PRIVILEGES after GRANT.
Force access via TCP/IP:
% mysql -u mysql -pmyPassword -h 127.0.0.1