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

最近操作mysql 5.6, 出现了以下问题。

分享,感谢原著:

案例环境:

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

[[email protected] tmp]# rpm -ivh MySQL-server-5.6.19-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
[[email protected] tmp]# rmp -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm 
-bash: rmp: command not found
[[email protected] tmp]# rpm -ivh MySQL-client-5.6.19-1.rhel5.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[[email protected] tmp]# /etc/rc.d/init.d/mysql status
MySQL is not running[FAILED]
[[email protected] tmp]# /etc/rc.d/init.d/mysql start
Starting MySQL.[  OK  ]
[[email protected] tmp]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[[email protected] 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服务器

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

[[email protected] init.d]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[2] 9396
[[email protected] 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)

  

    -> 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
[[email protected] 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
[[email protected] init.d]# mysql -u root p
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
[[email protected] 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/[email protected]/blog/static/164934572201081494343373/

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

作者:潇湘隐者

出处:http://www.cnblogs.com/kerrycode/

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

时间: 2024-10-26 06:41:19

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

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

环境:mac10.12 来源:http://www.cnblogs.com/kerrycode/p/3861719.html 使用root登录时遇到了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)错误. 如下所示 [[email protected] tmp]# rpm -ivh MySQL-server-5.6.19-1.rhel5.x86_64.rpm Preparing..

MySQL使用错误解决:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决方法: ⑴打开mysql中的my.ini(如果没有就将my-default.ini复制一份,并修改为my.ini): ⑵在[mysqld]下面空白行直接添加skip-grant-tables: ⑶重启mysql,在cmd页面输入mysql,按回车键即可. 注:这会使你的mysql无法设置密码,但对个人使用而言这岂不是更省了一步! MySQL使用错误解决:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using p

mySQL报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

一般这个错误是由密码错误引起,解决的办法自然就是重置密码. 假设我们使用的是root账户. 1.步骤一:跳过MySQL的密码认证过程#vim /etc/my.cnf(注:windows下修改的是my.ini) 在文档内搜索mysqld定位到[mysqld]文本段:/mysqld(在vim编辑状态下直接输入该命令可搜索文本内容) 在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程 保存文档并退出:#:wq 2.步骤二:重启MySQL:/etc/init.

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: MySQL安装时默认的用户是root,这里的root是指数据库的用户,root密码一般在初始化MySQL时存放在你的日志文件中,日志文件的存放路径可以通过my.cnf文件进行自定义. 使用如下方法即可解决,已验证可行. #1.停止mysql数据库 /etc/init.d/mysqld stop #2.执行

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

1 现象 mysql -u root -p 错误:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO/YES)2 linux系统: 在配置文件my-default.cnf或my.cnf下 [mysqld]下添加skip-grant-tables:因为此方法无效,所以找到了以下方法 为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error

Mysql5.7 CentOS7 报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

环境 Mysql5.7.24  CenOS 7.3.16 解决方案: 第一步: #systemctl stop mysqld.service 关闭mysql服务 第二步: #vim /etc/my.cnf 打开mysql配置文件 第三步: 最后面加入  skip-grant-tables 第四步: #systemctl start mysqld.service 打开MySQL服务 第四步: mysq -hlocal -uroot use mysql update user set authent

mac mysql连接报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

找了半天 又是kill进程,又是改设置文件,又是重启电脑,都不管用 翻到stackoverflow上的解决方案,实施成功: 原文链接:https://stackoverflow.com/questions/13480170/access-denied-for-mysql-error-1045 To restore it: Stop mysqld deamons. $ sudo service mysqld stop Go to mysql/bin directory $ cd /usr/bin

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

[[email protected] ~]# 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) 网上找了很多的文章还是没有解决我的问题: 1.首先可以确认的是mysql 命令行 sql命令关键字是不区

MySQL5.5出面ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)问题的解决办法

问题描述 安装完MySQL5.5数据库,使用Navicat Premium以及命令窗口连接数据库都报以下错误: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) 解决办法 通常该错误是忘记密码导致的,所以我们需要修改密码,具体操作步骤如下: 1.打开D:\Program Files\MySQL\MySQL Server 5.5\my.ini,在[mysqld]下增加一行启动参数