今天本地登入服务器的时候mysql提示:Mysql ERROR 1045 (28000)“Access denied for user ”

    解决方法:

   1. 因为我用的yum安装的,所以路径可以不用指定

   # /etc/init.d/mysql stop

   # mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
   # mysql -u root mysql
   mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
   mysql> FLUSH PRIVILEGES;
   mysql> quit
   # /etc/init.d/mysqld restart
   # mysql -uroot -p
   Enter password:
   mysql>

   2.如果是编译安装且安装路径为/usr/local/mysql,解决方法:

[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

Enterpassword: ******

[root@localhost mysql]#
/usr/local/mysql/ bin/mysql -u root mysql

mysql> update user set password=PASSWORD('123456') where user='root';

mysql> flush privileges;

[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p

mysql>