在博客Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)里面,我介绍了一下安装MySQL后登陆MySQL时会遇到ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 这个错误,当时不知道真正的原因,搜索了一些网上的资料,测试验证了如何解决这个问题,但是一直不知道具体的原因。今天终于把这个问题给彻底搞清楚了。

下面我以MySQL 5.6.20为例子,刨析一下这个错误的真正原因,如下所示

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

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

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

warning: user mysql does not exist - using root

warning: group mysql does not exist - using root

2015-03-26 10:49:06 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-03-26 10:49:07 5082 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-03-26 10:49:07 5082 [Note] InnoDB: The InnoDB memory heap is disabled

2015-03-26 10:49:07 5082 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-03-26 10:49:07 5082 [Note] InnoDB: Memory barrier is not used

2015-03-26 10:49:07 5082 [Note] InnoDB: Compressed tables use zlib 1.2.3

2015-03-26 10:49:07 5082 [Note] InnoDB: Using Linux native AIO

2015-03-26 10:49:07 5082 [Note] InnoDB: Using CPU crc32 instructions

2015-03-26 10:49:07 5082 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2015-03-26 10:49:07 5082 [Note] InnoDB: Completed initialization of buffer pool

2015-03-26 10:49:07 5082 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2015-03-26 10:49:07 5082 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

2015-03-26 10:49:07 5082 [Note] InnoDB: Database physically writes the file full: wait...

2015-03-26 10:49:07 5082 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

2015-03-26 10:49:07 5082 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

2015-03-26 10:49:08 5082 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

2015-03-26 10:49:08 5082 [Warning] InnoDB: New log files created, LSN=45781

2015-03-26 10:49:08 5082 [Note] InnoDB: Doublewrite buffer not found: creating new

2015-03-26 10:49:08 5082 [Note] InnoDB: Doublewrite buffer created

2015-03-26 10:49:08 5082 [Note] InnoDB: 128 rollback segment(s) are active.

2015-03-26 10:49:08 5082 [Warning] InnoDB: Creating foreign key constraint system tables.

2015-03-26 10:49:08 5082 [Note] InnoDB: Foreign key constraint system tables created

2015-03-26 10:49:08 5082 [Note] InnoDB: Creating tablespace and datafile system tables.

2015-03-26 10:49:08 5082 [Note] InnoDB: Tablespace and datafile system tables created.

2015-03-26 10:49:08 5082 [Note] InnoDB: Waiting for purge to start

2015-03-26 10:49:08 5082 [Note] InnoDB: 5.6.20 started; log sequence number 0

2015-03-26 10:49:08 5082 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.

2015-03-26 10:49:08 5082 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.

A random root password has been set. You will find it in '/root/.mysql_secret'.

2015-03-26 10:49:09 5082 [Note] Binlog end

2015-03-26 10:49:09 5082 [Note] InnoDB: FTS optimize thread exiting.

2015-03-26 10:49:09 5082 [Note] InnoDB: Starting shutdown...

2015-03-26 10:49:10 5082 [Note] InnoDB: Shutdown completed; log sequence number 1625977

 

 

2015-03-26 10:49:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-03-26 10:49:10 5104 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-03-26 10:49:10 5104 [Note] InnoDB: The InnoDB memory heap is disabled

2015-03-26 10:49:10 5104 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-03-26 10:49:10 5104 [Note] InnoDB: Memory barrier is not used

2015-03-26 10:49:10 5104 [Note] InnoDB: Compressed tables use zlib 1.2.3

2015-03-26 10:49:10 5104 [Note] InnoDB: Using Linux native AIO

2015-03-26 10:49:10 5104 [Note] InnoDB: Using CPU crc32 instructions

2015-03-26 10:49:10 5104 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2015-03-26 10:49:10 5104 [Note] InnoDB: Completed initialization of buffer pool

2015-03-26 10:49:10 5104 [Note] InnoDB: Highest supported file format is Barracuda.

2015-03-26 10:49:10 5104 [Note] InnoDB: 128 rollback segment(s) are active.

2015-03-26 10:49:10 5104 [Note] InnoDB: Waiting for purge to start

2015-03-26 10:49:10 5104 [Note] InnoDB: 5.6.20 started; log sequence number 1625977

2015-03-26 10:49:10 5104 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.

2015-03-26 10:49:10 5104 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.

2015-03-26 10:49:10 5104 [Note] Binlog end

2015-03-26 10:49:10 5104 [Note] InnoDB: FTS optimize thread exiting.

2015-03-26 10:49:10 5104 [Note] InnoDB: Starting shutdown...

2015-03-26 10:49:12 5104 [Note] InnoDB: Shutdown completed; log sequence number 1625987

 

 

 

 

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in '/root/.mysql_secret'.

 

You must change that password on your first connect,

no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

 

Also, the account for the anonymous user has been removed.

 

In addition, you can run:

 

  /usr/bin/mysql_secure_installation

 

which will also give you the option of removing the test database.

This is strongly recommended for production servers.

 

See the manual for more instructions.

 

Please report any problems at http://bugs.mysql.com/

 

The latest information about MySQL is available on the web at

 

  http://www.mysql.com

 

Support MySQL by buying support/licenses at http://shop.mysql.com

 

WARNING: Found existing config file /usr/my.cnf on the system.

Because this file might be in use, it was not replaced,

but was used in bootstrap (unless you used --defaults-file)

and when you later start the server.

The new default config file was created as /usr/my-new.cnf,

please compare it with your file and take the changes you need.

MySQL的安装日志信息中,你会看到MySQL生成了root用户的随机密码(如下截图所示),并将这个随机密码放置在/root/.mysql_secret中。并且强制在第一次登陆时修改root用户的密码。Mysql 5.6及以后版本出处于安全考虑,root密码不为空。所以在MySQL的安装过程中,会生成一个随机密码,但是对于我们这样的初学者,不了解情况,于是便从网上搜索如何解决问题的资料,而问题关键在此,很多做技术的人,了解不够深入,又喜欢随波逐流,停留在问题的表层,并未深入研究。而高手又不屑于这类简单的问题。

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,

no other statement but 'SET PASSWORD' will be accepted.

See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

知道了错误的前因后果,那么很容易就搞定这个问题了。找到随机密码,登录数据库后修改密码。问题解决

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

Enter password: 

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

Your MySQL connection id is 8

Server version: 5.6.20-enterprise-commercial-advanced

 

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> show databases;

ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

mysql> set password=password('wer@34');

Query OK, 0 rows affected (0.03 sec)

 

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| test               |

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

4 rows in set (0.00 sec)

MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)的真正原因的更多相关文章

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

    安装mysql后,使用命令登录mysql居然报错了,Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using ...

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

    MySQL安装完server端和客户端后,登录Mysql时报错:[root@rhel204 MySQL 5.6.23-RMP]# mysqlERROR 2002 (HY000): Can't conn ...

  3. [mysql] ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

    用mysql -u root -p显示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YE ...

  4. MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的解决办法和原因

    这两天下载了MySQL5.7.11进行安装,发现到了初次使用输入密码的时候,不管怎样都进不去,即使按照网上说的在mysqld 下面添加skip-grant-tables也是不行,后来研究了两天,终于找 ...

  5. Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    案例环境: 操作系统 :Red Hat Enterprise Linux Server release 5.7 (Tikanga) 64 bit 数据库版本 : Mysql 5.6.19 64 bit ...

  6. 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)) 修改: # ...

  7. 安装mysql因为/tmp权限不足而导致ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)的解决方案

    本机是centos 6.5  安装的mysql是5.1的版本. 在安装mysql之后,第一次启动mysql服务的时候,需要/tmp有777(rwxrwxrwx)的权限,然而楼主的/tmp是755(rw ...

  8. MySQL学习笔记——ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

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

  9. 重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    出现报错: Warning: World-writable config file '/etc/my.cnf' is ignored // 该文件权限过高ERROR 1045 (28000): Acc ...

随机推荐

  1. ubuntu super daemon设置

    super daemon是一个在Linux下面全面管理自己服务设置的东东,他可以接管很多服务的设定,只需要在/etc/xinetd.d/下面放置好自己的配置文件就可以了,那么,具体应该怎么配置呢?   ...

  2. js的并行加载以及顺序执行

    重新温习了下这段内容,发现各个浏览器的兼容性真的是搞大了头,处理起来很是麻烦. 现在现总结下并行加载多个js的方法: 1,对于动态createElement('script')的方式,对所有浏览器都是 ...

  3. [python]CentOS 6下安装Python2.7

    安装方法 如果在CentOS上自己编译安装过python2.7,使用过程中会发现有些标准库没有安装之类的问题. 逛别人博客的时候发现,一个便捷的方法:使用RHSCL的全称是Red Hat Softwa ...

  4. 9.Struts2在Action中获取request-session-application对象

    为避免与Servlet API耦合在一起,方便Action类做单元测试. Struts2对HttpServletRequest.HttpSession.ServletContext进行了封装,构造了三 ...

  5. 【Spring-web】RestTemplate源码学习

     2016-12-22   by 安静的下雪天  http://www.cnblogs.com/quiet-snowy-day/p/6210288.html 前言 在Web开发工作中,有一部分开发任务 ...

  6. WebSocket in ASP.NET Core

    一.WebSocket WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算) 首先HTTP有1.1和1.0 ...

  7. Linux打包与压缩及tar命令详解

    打包和压缩   在linux中,打包和压缩可以说是两个不同的概念,弄清这两个概念对于我们理解复杂的文件后缀有非常大的帮助 打包 将若干个文件和目录打包在一起变成一个大的文件,这时只是简单的打包,所以一 ...

  8. 自定义UIButton

    偶尔逛简书能看见很多值得记下来的东西,有的接触过有的没接触过,接触过的也可能过段时间就忘记了,再上手的时候可能手足无措,所以决定有些觉得值得记下来的东西还是记录一下.博客是个好地方,因为很多人都能搜索 ...

  9. 使用QUnit进行自动化单元测试

    前言 前阵子由于项目需求接触了java的单元测试JUnit,就顺带着学习了前端的单元测试:Qunit. 既然跟测试有关,不妨介绍一下测试中的黑盒测试.白盒测试以及单元测试. 1.黑盒测试:所谓的黑盒, ...

  10. C#+JQuery+.Ashx+百度Echarts实现全国省市地图和饼状图动态数据图形报表的统计

    在目前的一个项目中,需要用到报表表现数据,这些数据有多个维度,需要同时表现出来,同时可能会有大量数据呈现的需求,经过几轮挑选,最终选择了百度的echarts作为报表基础类库.echarts功能强大,界 ...