简体   繁体   中英

Access denied for user ''@'localhost'

Hi guys i've been stuck on this issue for the past hour. I've read online that i have to change the privileges for the user on mysql. I have done this and the user has been granted all privileges yet i still get the error! when i enter SHOW GRANTS FOR 'root'@'localhost'; it returns with

+---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+ +---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+ Any help would be much appreciated i just cant seem to find anything that works.

Looks like you're not providing a user - ''@'localhost'. It's also difficult to troubleshoot with no code examples provided.

Localhost and 127.0.1 are not treated the same for connection to mySQL so just change the $servername to localhost or grant privileges to root@127.0.0.1

From the docs:

On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option.

So it is,

Access denied for user 'root'@'localhost'

But again you are not providing the complete information, Check which one of these two you are getting, We will provide next steps based on that

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Yes)

Also, if you are not able to login mysql prompt as root, how then you are able to see SHOW GRANTS ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM