设为首页 收藏本站
查看: 1218|回复: 0

[经验分享] Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-7-23 09:30:24 | 显示全部楼层 |阅读模式
本帖最后由 ere12 于 2014-7-23 09:31 编辑

案例环境:

             操作系统 :Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit

          数据库版本 : Mysql 5.6.19 64 bit

案例介绍:

今天开始学习mysql,遂先安装了Mysql 5.6.19 64bit 版本的数据库,结果安装成功了,但是使用root登录时遇到了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)错误. 如下所示

[iyunv@DB-Server tmp]# rpm -ivh MySQL-server-5.6.19-1.rhel5.x86_64.rpm

Preparing...                ########################################### [100%]

   1:MySQL-server           ########################################### [100%]

[iyunv@DB-Server tmp]# rmp -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm

-bash: rmp: command not found

[iyunv@DB-Server tmp]# rpm -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm

Preparing...                ########################################### [100%]

   1:MySQL-client           ########################################### [100%]

[iyunv@DB-Server tmp]# /etc/rc.d/init.d/mysql status

MySQL is not running[FAILED]

[iyunv@DB-Server tmp]# /etc/rc.d/init.d/mysql start

Starting MySQL.[  OK  ]

[iyunv@DB-Server tmp]# mysql -u root -p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[iyunv@DB-Server tmp]# mysql -u root mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

222332429473234.jpg


安装过程中没有设置过root密码,不清楚root密码,搜索了网上一些资料,大致有下面一些情况:

1:有些博客说root的随机密码位于/root/.mysql_secret中,但是我这个版本根本没有/root/.mysql_secret文件。搜索到一篇文章,大意如下所示(没有确认)。到现在也没有明白,我这个版本为什么没有生成这个文件?

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) :表示没有生成root的临时密码

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) :表示生成了root的临时密码。

2:有些资料说root的默认密码为空,经过确认那是以前的老版本,Mysql 5.6及以后版本出处于安全考虑,root密码已经不为空了。

另外,我在官网论坛居然发现有很多人遇到类似问题ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法:

首先停掉mysql服务器

[iyunv@DB-Server init.d]# /etc/rc.d/init.d/mysql stop



Shutting down MySQL..[ OK ]



然后使用mysqld_safe命令在启动mysql,更新root账号的密码

--skip-grant-tables:不启动grant-tables(授权表),跳过权限控制。

--skip-networking :跳过TCP/IP协议,只在本机访问(从网上有些资料看,这个选项不是必须的。可以不用)

[iyunv@DB-Server init.d]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

[2] 9396

[iyunv@DB-Server init.d]# 140722 14:59:46 mysqld_safe Logging to '/var/lib/mysql/DB-Server.err'.

140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

执行上面命令后,此会话窗口会出现无反应的状态,需要使用CTRL+C中断会话,检查/var/lib/mysql/DB-Server.err日志,发现也无其它异常信息。没有弄明白该会话窗口为啥会出现无响应状态。

tail -200 /var/lib/mysql/DB-Server.err | more



2014-07-22 14:59:41 9346 [Note] Shutting down plugin 'binlog'

2014-07-22 14:59:41 9346 [Note] /usr/sbin/mysqld: Shutdown complete



140722 14:59:41 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended

140722 14:59:46 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

2014-07-22 14:59:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timesta

mp server option (see documentation for more details).

2014-07-22 14:59:47 9516 [Note] Plugin 'FEDERATED' is disabled.

2014-07-22 14:59:47 9516 [Note] InnoDB: Using atomics to ref count buffer pool pages

2014-07-22 14:59:47 9516 [Note] InnoDB: The InnoDB memory heap is disabled

2014-07-22 14:59:47 9516 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2014-07-22 14:59:47 9516 [Note] InnoDB: Compressed tables use zlib 1.2.3

2014-07-22 14:59:47 9516 [Note] InnoDB: Using Linux native AIO

2014-07-22 14:59:47 9516 [Note] InnoDB: Using CPU crc32 instructions

2014-07-22 14:59:47 9516 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2014-07-22 14:59:47 9516 [Note] InnoDB: Completed initialization of buffer pool

2014-07-22 14:59:47 9516 [Note] InnoDB: Highest supported file format is Barracuda.

2014-07-22 14:59:47 9516 [Note] InnoDB: 128 rollback segment(s) are active.

2014-07-22 14:59:47 9516 [Note] InnoDB: Waiting for purge to start

2014-07-22 14:59:47 9516 [Note] InnoDB: 5.6.19 started; log sequence number 1626087

2014-07-22 14:59:47 9516 [Note] /usr/sbin/mysqld: ready for connections.

Version: '5.6.19'  socket: '/var/lib/mysql/mysql.sock'  port: 0  MySQL Community Server (GPL)

222332458544746.jpg

[iyunv@DB-Server init.d]# mysql -u root mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A



Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.19 MySQL Community Server (GPL)



Copyright (c) 2000, 2014, 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> select Host, User, Password,password_expired

    -> from user

    -> where user='root' and host='root' or host='localhost';

+-----------+------+-------------------------------------------+------------------+

| Host      | User | Password                                  | password_expired |

+-----------+------+-------------------------------------------+------------------+

| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y                |

+-----------+------+-------------------------------------------+------------------+

1 row in set (0.00 sec)



mysql> update user set password=PASSWORD('p12#456')

    -> where user='root' and host='root' or host='localhost';

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)



mysql> quit

Bye

[iyunv@DB-Server init.d]# /etc/rc.d/init.d/mysql restart

Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended

[  OK  ]

Starting MySQL.[  OK  ]

[2]-  Done                    mysqld_safe --user=mysql --skip-grant-tables --skip-networking

[iyunv@DB-Server init.d]# mysql -u root p

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[iyunv@DB-Server init.d]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.19



Copyright (c) 2000, 2014, 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>

至此问题解决,但是还有不少地方有些疑惑,为啥出现这个错误? 其实这么多资料都只是说了解决方法,但是都回避了问题的原因。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-22553-1-1.html 上篇帖子: mysql数据库导入和导出 下篇帖子: MySQL创建用户与授权方法实例精讲
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表