在博客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: NO)

    下安装MySQL后登陆MySQL时会遇到ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: N ...

  2. ubuntu安装mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES

    通过apt安装方法十分简单,而且这种安装方法安装的mysql版本都是当前最新的版本.这种方式安装好后开机自启动都已经配置好,包括命令行的环境变量,无需手动配置. 如果出现以下问题 ERROR 1045 ...

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

    不用怀疑!是密码不对,如果密码确认输入正确,那么肯定是有人改过root密码了. 怎么重置密码呢? 1. 执行 vim /etc/mysql/my.cnf   ,打开文件后,找到mysqld关键字,在m ...

  4. MySQL在登陆时出现ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)错误...

    错误显示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 解决方案: 1.找到配 ...

  5. windows 下 安装mysql 出现 “ ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password

    这个问题是在Windows下安装MySQL服务时遇到的,使用MySQl绿色版进行安装的,安装完成后,连接到MySQL服务时输入命令 " mysql -uroot -p " ,因为时 ...

  6. CentOS7安装MySQL初始密码设置:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:

    晕,找了好半天终于找到了,在这里做个笔记. 解决错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pass ...

  7. 解决Mysql ERROR 1045 (28000)“Access denied for user 'root'@'localhost'”

    今天本地登入服务器的时候mysql提示:Mysql ERROR 1045 (28000)"Access denied for user 'root'@'localhost'" 解决 ...

  8. mac使用mysql出现的错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

    mac使用mysql出现的错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ...

  9. mysql安装在centos7报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    [问题]: mysql版本:5.7.13 首次在centos下安装mysql,客户端连接mysql时报错: [plain]  view plain  copy [root@localhost opt] ...

最新文章

  1. IPython、python shell(command line)、pycharm,python,python IDLE的区别是什么?
  2. Qt designer设计界面
  3. 超级楼梯HDOJ2041
  4. boost::sort模块实现跨并行线程的整数排序速度基准的测试程序
  5. 《大话数据结构》一些基础知识
  6. 限时|领取黄博士整理的人工智能数学资料
  7. 淘宝开放平台SDK对接
  8. 海量小文件存储(转)
  9. 谁是杨强?首位AAAI华人主席,身兼5大顶级组织Fellow,也是华为诺亚方舟实验室开创者...
  10. Ubuntu 使用 Cron 实现计划任务
  11. 17个值得收藏的国内外短信接码平台合集
  12. AI工具栏为两栏,工具栏显示不完全
  13. 运用深度学习进行文本生成
  14. 【历史上的今天】5 月 26 日:美国首个计算机软件程序专利;苹果市值首次超越微软;Wiki 的发明者出生
  15. apkrenamer_不怕应用名字乱 在手机端轻松给APK重命名
  16. 循环语句介绍(笔记学习)
  17. 【2018/10/11】T3 - 0/1分数规划 - 葫芦
  18. Reallusion iClone Pro(实时3d动画设计软件)官方正式版V7.92.5425.1 | 含iclone7安装教程以及iclone7设置中文方法
  19. slam之视觉+IMU
  20. M1芯片Mac mini外接显示器的各种问题

热门文章

  1. 记一次诡异的SpringMVC中拦截路径的问题
  2. Jenkins系统上的时间不正确问题
  3. C# 移动开发(Xamarin.Form) Plugin.BLE 蓝牙连接
  4. FAQ接口自动化_转载参考
  5. 版本号控制-搭建gitserver
  6. 初学spring(一)
  7. u-boot分析——struct gd_t与struct bd_t
  8. 树与二叉树的深度优先与广度优先算法(递归与非递归)
  9. 聊一聊社交网络的逻辑、产品和未来
  10. 如何判断网站是否启用HTTP2