Access denied for user 'root'@'localhost' (using password:YES)
一、Windows平台下mysql 1054错误:
进入dos命令行,切换到你的MySQL bin目录下
比如我的是 D:\Program Files\MySQL\MySQL Server 5.0\bin --(注意自己的my.ini位置)
C:\Users\Administrator>d:
D:\>cd Program Files\MySQL\MySQL Server 5.0\bin
D:\Program Files\MySQL\MySQL Server 5.0\bin>
D:\Program Files\MySQL\MySQL Server 5.0\bin>mysqld-nt --defaults-file="D:\Program Files\MySQL\MySQL Server 5.0\my.ini" --console --skip-grant-tables
140116 10:55:29 InnoDB: Started; log sequence number 0 289705428
140116 10:55:29 [Note] mysqld-nt: ready for connections.
Version: '5.0.96-community-nt' socket: '' port: 3306 MySQL Community Edition (GPL)
看到红色字体一行就说明MySQL已经起来了。
另外再开一个DOS窗口,同样切到mysql bin目录下
D:\Program Files\MySQL\MySQL Server 5.0\bin>
mysql -uroot mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.96-community-nt MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit
然后关闭mysql服务
D:\Program Files\MySQL\MySQL Server 5.0\bin>mysqladmin shutdown
之后正常重启MySQL服务就行了。
D:\Program Files\MySQL\MySQL Server 5.0\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password: ********* --<这里输入刚刚重置的新密码>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.96-community-nt MySQL Community Edition (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
二、在Linux平台中Mysql访问是,提示1054错误
# /etc/init.d/mysqld stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -uroot mysql
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.1.73-community MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>