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.
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;
The command:
mysql -u root -p
gives the error:
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
But running sudo privileges, works:
sudo mysql -u root -p
Is it possible to get rid of the sudo requirement because it prevents me from opening the database in intellij? I tried the following as in the answer to this question Connect to local MySQL server without sudo:
sudo chmod -R 755 /var/lib/mysql/
which did not help. The above question has a different error thrown
Only the root user needs sudo requirement to login to mysql. I resolved this by creating a new user and granting access to the required databases:
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'#'localhost';
now newuser can login without sudo requirement:
mysql -u newuser -p
You need to change algorithm. Following work for me,
mysql > ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
mysql > FLUSH PRIVILEGES;
You can use the same ROOT user, or a NEW_USER and remove the SUDO privileges. Below example shows how to remove connect using ROOT, without SUDO.
Connect to MY-SQL using SUDO
sudo mysql -u root
Delete the current Root User from the User Table
DROP USER 'root'#'localhost';
Create a new ROOT user (You can create a different user if needed)
CREATE USER 'root'#'%' IDENTIFIED BY '';
Grant permissions to new User (ROOT)
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
Flush privileges, so that the Grant tables get reloaded immediately. (Why do we need to flush privileges?)
FLUSH PRIVILEGES;
Now it's all good. Just in case, check whether a new root user is created.
SELECT User,Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| root | % |
| debian-sys-maint | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
Exit mysql. (Press CTRL + Z). Connect to MySQL without SUDO
mysql -u root
Hope this will help!
first login to your mysql with sudo.
then use this code to change "plugin" coloumn value from "unix_socket" or "auth_socket" to "mysql_native_password" for root user.
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin IN ('unix_socket', 'auth_socket');
FLUSH PRIVILEGES;
finally restart mysql service. that's it.
if you want more info, check this link
UPDATE:
In new versions of mysql or mariadb you can use :
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password USING PASSWORD('your-password');
FLUSH PRIVILEGES;
I have solved this problem using following commands.
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'username'#'localhost';
FLUSH PRIVILEGES;
Here,
username = any user name you like.
and password = any password you like.
You can use the below query:
GRANT ALL PRIVILEGES ON *.* TO 'username'#'localhost' IDENTIFIED BY 'password';
This query is enough.
This answer needs to be slightly adapted for mariaDB instead of mysql.
First login as root using sudo:
$ sudo mysql -uroot
Then alter the mariadb root user:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password USING PASSWORD('mypassword');
FLUSH PRIVILEGES;
From now on sudo is not longer needed:
$ mysql -uroot -p
Version used:
mysql Ver 15.1 Distrib 10.4.13-MariaDB, for osx10.15 (x86_64) using readline 5.1
Login to mysql with sudo:
sudo mysql -u root -p
After that Delete current root#localhost account:
~ MariaDB [(none)]> DROP USER 'root'#'localhost';
~ MariaDB [(none)]> CREATE USER 'root'#'localhost' IDENTIFIED BY 'password';
~ MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION;
~ MariaDB [(none)]> FLUSH PRIVILEGES;
In the comment of the question you answer you referenced, it reads
Ok, just try to analyze all of the directories down in the path of the
socket file, they need to have o+rx and the sock file too (it's not a
good idea to make it modifiable by others).
You can also try to remove mysql.sock and then restart mysqld, the
file should be created by the daemon with proper privileges.
This seemed to work for this question(the one you said you looked at) so it may work for you as well
The error Message:
"ERROR 1698 (28000): Access denied for user 'root'#'localhost'"
means that the Server not allow the connect for this user and not that mysql cant access the socket.
try this to solve the problem:
Login in your DB
sudo mysql -u root -p
then make these modifications:
MariaDB []>use mysql;
MariaDB [mysql]>update user set plugin=' ' where User='root';
MariaDB [mysql]>flush privileges;
MariaDB [mysql]>exit
try login again without sudo
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