教程集 www.jiaochengji.com
教程集 >  数据库  >  mysql  >  正文 mysql报错:“Access denied for user 'root'@'localhost'”的解决方法

mysql报错:“Access denied for user 'root'@'localhost'”的解决方法

发布时间:2015-10-09   编辑:jiaochengji.com
ubuntu系统下,新装好的mysql在进入mysql工具时,总是有错误提示:

ubuntu系统下,新装好的mysql在进入mysql工具时,总是有错误提示:
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
 
参照网上介绍的方法,修改root的密码:
 

复制代码 代码如下:
# mysqladmin -uroot -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'

正确的解决方法,如下(请先测试方法三):
 
方法一:
 

复制代码 代码如下:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
 
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
 
mysql>

方法二:
直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:
 

复制代码 代码如下:
# mysql -udebian-sys-maint -p
Enter password: <输入[client]节的密码>
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
 
mysql> FLUSH PRIVILEGES;
mysql> quit
 
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
 
mysql>

方法三:
这种方法我没有进行过测试,因为我的root用户默认密码已经被我修改过了,那位有空测试一下,把结果告诉我,谢谢!
 

复制代码 代码如下:
# mysql -uroot -p
Enter password: <输入/etc/mysql/debian.cnf文件中[client]节提供的密码>

问题解决了,仰望星空,万里无云,哈!!!

您可能感兴趣的文章:
mysql报错:“Access denied for user 'root'@'localhost'”的解决方法
mysql Access denied for user 'root'@'localhost' 问题的解决方法
phpmyadmin 配置方法与安装教程
MySQL执行GRANT命令时报错ERROR 1045解决办法
ubuntu10.10中修改mysql root用户密码的方法
Linux下mysql允许远程连接怎么设置?
linux下mysql用户管理方法
php报错Permission denied的解决一法
php error Can't connect to local MySQL server...的解决方法
mysql授权服务器用户登录到主服务器的方法详解

[关闭]
~ ~