mysqllocalhost没法登录

关于mysql localhost没法登录的问题

提示”ACCESS DENIED FOR USER ‘ROOT’@’LOCALHOST’ (USING PASSWORD: YES)”

1.是否被修改了root密码

  • /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

    2.localhost是否没有映射到root

    • mysql -u root -p -h 127.0.0.1
      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;
  • select user,host,password from user; 再查询用户表
  • mysql -h localhost和mysql -h 127.0.0.1的区别,经过localhost链接到mysql是使用UNIX socket,而经过127.0.0.1链接到mysql是使用TCP/IP
  • 查看状态 mysql -h localhost > status问题解决。