The difference between mysql-h localhost and mysql-h 127.0.0.1

Source: Internet
Author: User

My colleague said this morning that the MySQL root account was not logged in. I tried.
#mysql-U root-p
Tip "Access denied for user ' root ' @ ' localhost ' (using Password:yes)"

I was the first person who changed the root password because of the resignation of a colleague after years. Follow the forgot root password to reset your password:
#/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

With a new password or unable to log in, the prompt is the same as above. For a non-root account login, 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, sure enough to log in.
Prior to configuring the database The classmate did not give the ' root ' @ ' localhost ' and ' root ' @ ' IP ' authorization.
Grant all privileges the ' root ' @ ' localhost ' identified by ' mypassword ' with GRANT option;
Grant all privileges the ' root ' @ ' 118.192.91.xxx ' identified by ' mypassword ' with GRANT option;

Check the user table again:

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

Check the difference between mysql-h localhost and mysql-h 127.0.0.1, connect to MySQL via localhost using UNIX socket , Connecting to MySQL via 127.0.0.1 is using TCP/IP . Look at the status:  
mysql-h localhost > Status  
Connection ID:     639 
Current DATABASE:MYSQL&NBSP,
Current User:   [email protected] 
SSL:         & nbsp 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: [email protected]
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

Workaround
Added in My.cnf's [MySQL] section

Protocol=tcp

Save restart MySQL, problem solution
Summary

[Email protected]% means all access can be

[Email protected] indicates that localhost can access

The difference between mysql-h localhost and mysql-h 127.0.0.1

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.