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