MySQL & #39; root & #39; @ & #39; localhost & #39; login failure, mysqllocalhost

Source: Internet
Author: User

MySQL 'root' @ 'localhost' cannot be logged on, mysqllocalhost

This morning, my colleague said that the MySQL root Account could not be logged on. I tried it.
# Mysql-u root-p
Prompt "Access denied for user 'root' @ 'localhost' (using password: YES )"

Because a colleague resigned after the year, my first response was: Who modified the root password? Reset the password Based on the root password you forgot:
#/Etc/init. d/mysql stop
# Mysqld_safe-skip-grant-tables &
# Mysql-uroot-p
Mysql> update mysql. user set password = password ('mypassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit

You still cannot log on with the new password. The prompt is the same as above. Log on to another non-root account and check the user table:
Mysql> select user, host from user;
+ ---- + --- +
| User | host |
+ ---- + --- +
| Root | 127.0.0.1 |
| Night | % |
+ ---- + --- +

Suspect that the default localhost is not mapped to 127.0.0.1? Try # mysql-u root-p xxxx-h 127.0.0.1. you can log on.
Previously, the Database Configuration personnel did not grant 'root' @ 'localhost' and 'root' @ 'IP' authorization.
Grant all privileges on.To 'root' @ 'localhost' identified by 'mypassword' with grant option;
Grant all privileges on.To 'root' @ '118. 192.91.xxx' identified by 'mypassword' with grant option;

Query the user table again:

Then # mysql-u root-p xxxx, login successful!

Check the difference between mysql-h localhost and mysql-h 127.0.0.1.UNIX socketAnd connect to mysql through 127.0.0.1 is to useTCP/IP. Check the status:
Mysql-h localhost> status
Connection id: 639
Current database: mysql
Current user: root @ localhost
SSL: Not in use
Current pager: stdout
Using outfile :"
Using delimiter :;
Server version: 5.6.15-log Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket

Mysql-h 127.0.0.1> status
Connection id: 640
Current database: mysql
Current user: root @ localhost
SSL: Not in use
Current pager: stdout
Using outfile :"
Using delimiter :;
Server version: 5.6.15-log Source distribution
Protocol version: 10
Connection: 127.0.0.1 via TCP/IP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.