介绍了一下安装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.

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

linux mysql提示1045_linux mysql ERROR 1045相关推荐

  1. Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (usin

    Linux mysql 5.6: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pass... 时间 201 ...

  2. 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) ...

  3. windows mysql 登录报错 ERROR 1045 已解决

    mysql版本:8.0.28 问题:用 root 用户登录报错提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (usi ...

  4. mysql报错:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘

    在Ubuntu安装好MySQL后报错 安装命令(Ubuntu 20.04): sudo apt install mysql-server sudo systemctl start mysql.serv ...

  5. mysql登录报错 ERROR 1045 (28000)

    1.现象: [root@localhost ~]# mysql -u root -p Enter password:  ERROR 1045 (28000): Access denied for us ...

  6. MYSQL重置密码遇到ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using passwor:yes)问题

    一般这个错误是由密码错误引起,解决的办法自然就是重置密码. 假设我们使用的是root账户. 1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下: #vim /etc/my.cnf(注:wi ...

  7. mysql报错:ERROR 1045 (28000): Access 解决办法

    2019独角兽企业重金招聘Python工程师标准>>> Ubant Mysql 突然就这样了. 网上查了些办法,解决办法: # /etc/init.d/mysql stop  # m ...

  8. 【mysql 登录故障】ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using passwor:yes)

    前言:这是一个比较常见的问题,但是触发原因众说纷纭,目前我还没能够找到最信服的原因.网上比较多的说法是 a.因为多次密码输错的原因. b.因为mysql服务没正常启动. c.因为data所在的盘空间不 ...

  9. 非正常关机导致无法启动MYSQL提示丢失mysql.sock的解决办法

    判断一般人解决故障时没有切换到mysql用户,造成权限有问题,无法创建mysql授权表,所以也就无法创建/tmp/mysql.sock 和hostname.pid文件.因此,总结解决方法如下: (1) ...

最新文章

  1. 从终端命令行运行 AppleScript 脚本
  2. eval并发 shell_Shell 实现多任务并发
  3. 巧用拦截器:高效的扩展点设计
  4. mybatisplus执行sql语句_一条更新的SQL语句是如何执行的?
  5. PaperNotes(19)-Learning Lane Graph Representations for Motion Forecasting
  6. Apache RocketMQ在我司的最佳实践--智慧政务场景下的分布式消息与分布式事务
  7. 前端每日实战:163# 视频演示如何用原生 JS 创作一个多选一场景的交互游戏(内含 3 个视频)...
  8. flask post json_Flask 和 requests 搭建一个简单的API服务
  9. POJ 2991 Crane(线段树+计算几何)
  10. android UI进阶之android中隐藏的layout 抽屉的运用
  11. 机器学习库线性回归代码_PyCaret回归:更好的机器学习库
  12. 用Origin将Fluent中的数据导出并绘制云图
  13. 传奇手游战神引擎开服教程架设教程工具全套图文教程
  14. 谈谈从PC端到移动端的产品设计差异
  15. Android项目的targetSDK=23,在低于Android6.0的部分测试机(类似华为)上运行时出现的系统权限问题...
  16. Python实现文件夹复制操作
  17. 解析grant connect, resource to user语句
  18. macbook 终端命令怎么使用_玩转 Terminal 终端:入门指南及进阶技巧
  19. 看完代码回首看论文:YOLOv3重读
  20. [转] 理解各种熵最大熵模型

热门文章

  1. [转帖]FPGA--Vivado
  2. 机器学习实战学习笔记 一 k-近邻算法
  3. 设置easyui input默认值
  4. hwnd = 0 各种粗心大意啊!
  5. linux的基础知识——协议和网络应用程序设计模式
  6. Spring --getBean用法
  7. 分层结构,协议,接口,服务
  8. java数组的四个要素_Java零基础系列教程04Java数组
  9. TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
  10. python方向键控制角色_用python和pygame游戏编程入门-控制角色移动