案例环境:

操作系统 :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)错误. 如下所示

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

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

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

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

-bash: rmp: command not found

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

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

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

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

MySQL is not running[FAILED]

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

Starting MySQL.[  OK  ]

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

Enter password: 

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

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

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

安装过程中没有设置过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服务器

[root@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协议,只在本机访问(从网上有些资料看,这个选项不是必须的。可以不用)

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

[2] 9396

[root@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)

[root@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

[root@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

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

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

[root@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> 

另外,如果登录mysql数据库后执行脚本遭遇 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,可以使用重新设置一次密码即可解决问题.

mysql>set password = password('p12#456'); 

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

参考资料:

http://huangyifa163.blog.163.com/blog/static/262875752011127102215790/

http://sundful.iteye.com/blog/704337

http://wenku.baidu.com/view/735ffa41be1e650e52ea995a.html

http://www.cnblogs.com/sunson/articles/2172086.html

http://blog.163.com/eric1945@126/blog/static/164934572201081494343373/

http://www.cnblogs.com/likai198981/archive/2013/04/06/3002518.html

Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的更多相关文章

  1. Ubuntu下MySQL报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    在Ubuntu下 想要登录mysql数据库 root@JD:~# mysql -uroot -p 报错 ERROR 1045 (28000): Access denied for user 'root ...

  2. MySQL报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:NO)

    1.关闭mysql   # service mysqld stop2.屏蔽权限   # mysqld_safe --skip-grant-table   屏幕出现: Starting demo fro ...

  3. MAC使用mysql报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    遇到这种错误,需要重置密码. Step1:停止mysql,命令如下: $ sudo service mysql stop 或者是 $ sudo /usr/local/mysql/support-fil ...

  4. Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    Mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) Linux: MyS ...

  5. mysql登录报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    在MySQL登录时出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问 对于出现拒绝访问root用户的解决方案错 ...

  6. mysql 安装完毕后登陆不了mysql的 shell 即mysql>遇到:ERROR 1045 (28000): Access denied for user 'root'@'localhost‘

    [root@hzswtb2-mpc ~]# mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pas ...

  7. 解决mysql:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)

    一.问题 有时候我们登录Mysql输入密码的时候,会出现这种情况 mysql -u root -p Enter Password > '密码' 错误:ERROR 1045 (28000): Ac ...

  8. win10连接mysql提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    win10中cmd连接mysql提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YE ...

  9. mysql 链接失败(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES))

    mysql链接失败(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)) 修改: # ...

随机推荐

  1. .NET 中Barcode Library的应用二

    .NET中Barcode Library的应用二 介绍 在上一篇中我已经简单介绍了这个函数库(条形码应用之一------------函数库的简介).在这一篇中我将使用这个库提供更多的操作,希望对大家有 ...

  2. hibernate笔记--缓存机制之 一级缓存(session缓存)

    一级缓存: 又称为session缓存,它和session生命周期相同,周期非常短.是事务级别的缓存: 还是以Book和Category这两个表为例,我们用代码观察一个缓存的存在: 假设现在我要去查询i ...

  3. jQuery 判断是否包含某个属性

    1.Get the attribute, check the value var attr = $(this).attr('name'); // For some browsers, `attr` i ...

  4. 家族/亲戚(relation)

    题目描述 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如果x,y是 ...

  5. Delphi 取得 iOS 辅助使用里的字型大小

    说明:在 iOS 里有一个人性化的辅助设定,可以将字体放大,但这个设定对 Delphi 是不起作用的,还好 Delphi 提供了这个 iOS API 可以取得. 开发环境:Delphi 10 Seat ...

  6. PHP JSON数组与对象的理解

    在PHP后端和客户端数据交互的过程中,JSON数据中有时格式不定,一会儿是数组,一会儿是对象,弄得客户端开发人员要崩溃的感觉. 因此,前后端相关人员先对PHP的json_encode函数原理有必要的了 ...

  7. 用Spring Boot颠覆Java应用开发

    Java开发概述: 使用Java做Web应用开发已经有近20年的历史了,从最初的Servlet1.0一步步演化到现在如此多的框架,库以及整个生态系统.经过这么长时间的发展,Java作为一个成熟的语言, ...

  8. 转载:《TypeScript 中文入门教程》 13、类型兼容性

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 介绍 TypeScript里的类型兼容性基于结构子类型的. 结构类型是只一种只使用其成 ...

  9. 微信公众平台自动回复wechatlib.jar的生成及wechatlib解析

    微信公众平台出来有一段时日了,官方提供的自动回复的接口调用大致是这么些类型(text/image/location/link),每个项目都如此拷贝代码,在笔者看来比较麻烦,今天乘着点闲暇的时间特意将这 ...

  10. 关于webStrom-11.1配置less且自动生成.css和自动压缩为.min.css/.min.js

    网上看过很多配置思路,自己总结了以下, 就把我个人配置的顺序以及材料分享下,webstrom以下简称WB 1.配置less需要安装nodejs,自行安装.因为要用到npm.我是直接把npm解压到C盘根 ...