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

Source: Internet
Author: User

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

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. Using localhost to connect to mysql uses UNIX socket, while using 127.0.0.1 to connect to mysql uses TCP/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

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

How to forget the MySQL root Password in Windows

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.