If you carefully check the MYSQL permission table, you will find that there are records with the Host Name localhost and the host name 127.0.0.1. When will these two records be used?
When you use/usr/local/mysql/bin/mysql-u root-p to access the MYSQL server, if the-h parameter is used, mysql will connect to the server through TCP/IP. Without the-h parameter, the UNIX socket method will be used by default.
If the connection comes in through TCP/IP, the MYSQL server receives 127.0.0.1 as the source host, and the UNIX socket method, the MYSQL server receives localhost as the source host.
If the MYSQL server enables skip_name_resolve, the MYSQL server will not convert the received IP address to a domain name, so the current_user of the former is root @ '127. 0.0.1 '. The current_user of the latter is root @ 'localhost '.
If skip_name_resovle is OFF according to the default MYSQL configuration, the MYSQL server will convert 127.0.0.1 to localhost, And the current_user connected to the former and later will be root @ 'localhost'